Try our conversational search powered by Generative AI!

Problem creating page in different languages programmatically


I'm using a multi-site solution and one of the sites is in "en", "fr" and "nl". I can create a page under my designated parent on "en" but not on "fr" or "nl" even though the parent has at least a "fr" version.
I get this exception when I try to save the new page:
"ContentReference was not set to a valid value
Parameter name: contentLink
Actual value was ContentReference.EmptyReference."

I'm using EPiServer CMS and this is the breakdown of the code that I'm using.

eventPage = contentRepository.GetDefault(eventContainer);
eventPage.Language = new System.Globalization.CultureInfo(language);

eventPage.ExternalURL = "/event_id/" + eventObject.event_id;
eventPage.PageName = eventObject.heading;
eventPage.URLSegment = UrlSegment.CreateUrlSegment(eventPage);

DataFactory.Instance.Save(eventPage, SaveAction.Publish, AccessLevel.NoAccess);

I've removed some code that fills in some more fields but I guess this is the more important part of the code.

Anyone that have had a similar problem?

Feb 17, 2016 10:51

I forgot to mention that it works to create a "fr" version of the page, if there is already a "en" version. Tried the other way around and it didn't work.

Feb 17, 2016 10:54

To create a page in a certain language you add the cultureinfo as a parameter to GetDefault.

contentRepository.GetDefault<StartPage>(eventContainer, new CultureInfo(language));

Btw, the UrlSegement is automatically set to pagename when saved. (If it's empty..)

Edited, Feb 17, 2016 12:22

Thanks! Actually just found it by myself also. :)

Feb 17, 2016 12:26
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.