The solution to this is to manually go into the CMS and click save and publish on the item which then loads the page without any errors and with all the images as expected...
var MainImageId = 123; //normally the id of the image that has just been uploaded.
var MainMediaUdi = Umbraco.TypedMedia(MainImageId.ToString());
Page.SetValue("mainImage", MainMediaUdi.GetUdi());
This issue is im getting is 'IPublishedContent' does not contain a definition for 'GetUdi' and no extension method 'GetUdi' accepting a first argument of type 'IPublishedContent' could be found (are you missing a using directive or an assembly reference?)
So it seems i getting IPublishedContent, is this a TypedMediaObject?
So when the code hits the part when it runs the GetUdi() it throws an error of "The best overloaded method match for 'Umbraco.Core.Models.ContentBase.SetPropertyValue(string, string)' has some invalid arguments"
The image is being added as i expect it to be, its also returning the Media MediaService item as expected...
System.FormatException: String "3553" is not a valid udi.
Hi,
I'm programmatically adding pages. These are being added successfully, but once trying to load the page on the website I get the following error:
This error is on the first image that the page loads. The error in this case is on:
The solution to this is to manually go into the CMS and click save and publish on the item which then loads the page without any errors and with all the images as expected...
Where am I going wrong?
Thanks, Lewis
anyone?
Hi Lewis,
umbraco introces the
UDI
identifier format from version 7.6.0+. You can find more information about the format in the docs:https://our.umbraco.org/documentation/reference/querying/Udi
Can you show use the code where you add a content page programmatically?
Normally you should use something like:
to get the
Udi
identifier of a published content object. Then to set this onto another page:Hope this helps!
/Michaël
Hi Michael,
There is a fair amount of code but here is the main part of it that i think you will be interested in...
This code is in a foreach loop hence the continue.
The values that are set for the images are (int) ids of the images that are uploaded.
The alias is set at the top (node.Alias) which is just a string of "watchProduct"
Thanks, Lewis
Hi Lewis,
so you are using
MediaPicker
for these images correct?In your code you have:
Which contains the id of the main image, using this Id get the typed media object using:
Then to get the Udi identifier use:
Then set this value:
Hope this helps!
PS: code not tested, manually written here!
/Michaël
Hi Michael,
So i have the following:
This issue is im getting is
'IPublishedContent' does not contain a definition for 'GetUdi' and no extension method 'GetUdi' accepting a first argument of type 'IPublishedContent' could be found (are you missing a using directive or an assembly reference?)
So it seems i getting IPublishedContent, is this a TypedMediaObject?
Thanks, Lewis
Lewis,
yes just changed my answer, was typing to fast. You need the
MediaService
to get the media file.Hope this helps!
/Michaël
Hi Michael,
So when the code hits the part when it runs the GetUdi() it throws an error of
"The best overloaded method match for 'Umbraco.Core.Models.ContentBase.SetPropertyValue(string, string)' has some invalid arguments"
The image is being added as i expect it to be, its also returning the Media MediaService item as expected...
thanks, Lewis
Hi Lewis,
you forgot to cast it to
ToString()
see my post above.Hope this helps!
/Michaël
-_- Work a treat! I will buy you a drink at codegarden this year!
Hi Lewis,
no problem!
I won't make it this year, but you can save the drink for another time when we meet!
Have a nice day
/Michaël
is working on a reply...