I'm creating a new page using the content service, and trying to set the value of a content picker of the new page using the code below
IContent c = contentService.Create(ic.Name, guid, "contentPage", -1);
c.SetCultureName(ic.Name, "en-US");
var locaUdi = Udi.Create(Constants.UdiEntityType.Document, ic.Key);
c.SetValue("content", locaUdi.ToString());
contentService.SaveAndPublish(c);
However, I keep getting the following error:
An exception of type 'System.NotSupportedException' occurred in Umbraco.Core.dll but was not handled in user code
Additional information: Variation "null,null" is not supported by the property type. occurred
I've had a look at this answer but still getting the error above.
I was wondering what the correct way would be to set the content for a content picker? I've tried using the Id and guid as well but neither of these seemed to work either
Because the error says: Variation "null,null" is not supported. It seems that the culture/variation is needed.
It is the same approach you already did with c.SetCultureName(ic.Name, "en-US"); for the content object. The same is needed for each value that is culture specific.
I haven't tried it myself yet, but I think when you set the Varying by culture property to false on the "content" property, the problem is solved too.
Setting Value for Content Picker
Hi,
I'm creating a new page using the content service, and trying to set the value of a content picker of the new page using the code below
However, I keep getting the following error:
I've had a look at this answer but still getting the error above.
I was wondering what the correct way would be to set the content for a content picker? I've tried using the Id and guid as well but neither of these seemed to work either
Hi Andrew,
Try setting the culture on the SetValue method like this:
Because the error says: Variation "null,null" is not supported. It seems that the culture/variation is needed.
It is the same approach you already did with
c.SetCultureName(ic.Name, "en-US");
for the content object. The same is needed for each value that is culture specific.I haven't tried it myself yet, but I think when you set the Varying by culture property to false on the "content" property, the problem is solved too.
Ah I see, brilliant thanks Corné, yeah that did the job! Thanks again for your help :)
Hi, could you please guide on where i have to add this value as i am new in Umbraco
is working on a reply...