but I'm still unable to get the value from the media picker.
On my last attempt, I got the following error.
Object reference not set to an instance of an object
If I try the following:
string img = "";
foreach (var d in archtypePanel.Properties)
{
if (d.Alias == "imageToDisplay")
{
img = d.Value.ToString();
}
}
I can see the media UDI: "umb://media/15cc14d318f3444a86ab3bc7fc5787ad" but I'm unable to get any further.
I have now run into a wall, so any help on solving this issue will be helpful.
My code is:
Guid idValue = new Guid(id);
var blogPosts = CurrentPage;
IPublishedContent blogPosts2 = CurrentPage;
var archtypePanel = blogPosts2.GetPropertyValue
ArchetypeWithTextAndImageModel model = new ArchetypeWithTextAndImageModel
{
TextContent = new HtmlString(archtypePanel.GetValue("textRichTextEditor")),
ImageId = archtypePanel.GetValue<IEnumerable<IPublishedContent>>("imageToDisplay").ToString()
};
Do you want to get the actual UDI or just the image? Assuming you have used the default MediaPicker datatype (Umbraco.MediaPicker2) set to pick single (not multiple) images then you can do this:
If you want just the image (as IPublishedContent) you should be able to go:
var image = archetypePanel.GetValue<IPublishedContent>("imageToDisplay");
<img src="'@image.Url" />
If you want the actual UDI then you can go:
var udi = archetypePanel.GetValue<IEnumerable<Udi>>("image").First();
string udiString = udiToString();
Umbraco 7 Archetype unable to get media udi
Hi
I have read these posts https://our.umbraco.org/forum/templates-partial-views-and-macros/85993-archetype-mediapicker-udi
https://our.umbraco.org/forum/using-umbraco-and-getting-started/85598-getting-image-url-from-media-picker-not-working-in-76
http://www.codeshare.co.uk/blog/how-to-get-the-file-path-of-a-media-item-in-umbraco/
but I'm still unable to get the value from the media picker.
On my last attempt, I got the following error.
Object reference not set to an instance of an object
If I try the following:
I can see the media UDI: "umb://media/15cc14d318f3444a86ab3bc7fc5787ad" but I'm unable to get any further.
I have now run into a wall, so any help on solving this issue will be helpful.
My code is:
Do you want to get the actual UDI or just the image? Assuming you have used the default MediaPicker datatype (Umbraco.MediaPicker2) set to pick single (not multiple) images then you can do this:
If you want just the image (as IPublishedContent) you should be able to go:
If you want the actual UDI then you can go:
NB. to get HTML content you can just go:
Hi Dan
My issue was a corrupt install of some Nuget packages, I removed all and reinstalled and now works OK.
Thanks for the reply.
is working on a reply...