Getting the Url of an image using MediaLibraryPickerField

Topics: Writing modules, Writing themes
Sep 9, 2013 at 3:48 AM
Hi, I added an image-avatar to the user part using MediaLibraryPickerField.
I just added an image!

Now, i want to get the url using razor!! I named the part added: Avatar, so i tried this:

((dynamic)(WorkContext.CurrentUser)).ContentItem.User.Avatar

this way i got the MediaLibraryPickerField!! but how the hell i get the url of the image, i don't understand this new Module and there is not documentation!!!

2 hours inspecting objects, and gessing parts and fields...!! this is annoying!!

For now i will use the deprecated MediaPickerField until someone throws the solution!!

Thx!
Coordinator
Sep 9, 2013 at 5:55 AM
Start by looking at MediaLibraryPickerField!!! Then, notice it has a MediaParts property that is an enumerable of MediaPart!!!!! Get the first of those using MediaParts.FirstOrDefault()!!!!!!!! If that's not null, look at its MediaUrl property! That's your url!!!!!!! Cheers!
Sep 10, 2013 at 3:54 PM
I will try bertrand!! thx!!! I will put here the solution if i find it!!!!!!!!!!!!!!!!!!
Coordinator
Sep 10, 2013 at 6:58 PM
Cool!!!!!!! :D
Sep 11, 2013 at 12:12 AM
Please do jusquiano as I'm failing dismally trying to do the same thing [as per: https://orchard.codeplex.com/discussions/455797]
Cheers Gil
Sep 20, 2013 at 4:33 PM
Ok, i found the solution today in 5 minutes!!! it was easy!!

((dynamic)WorkContext.CurrentUser.ContentItem).User.Avatar.MediaParts[0].MediaUrl;

I don't understand how was possible that i did not see the MediaPart... I think sometimes VS is tricky and hide things...

Anyway it was solved..

Thx!
Dec 4, 2013 at 4:56 AM
Thanks for the help on this. Due to the difficulty of examining the dynamic objects in VS, there's no way I would have figured this out without searching and finding this post.

Would it be possible to add better debug info on Shapes? I know there are a number of extensibility points for debugger information.
Developer
Dec 4, 2013 at 8:30 AM
Visual Studio already shows the properties of a shape (thanks to the debugger extensibility point). What more debug information do you think would be useful?
Dec 4, 2013 at 2:22 PM
Hey johncrim! Nice to hear this worked for u!