November Happy Hour will be moved to Thursday December 5th.

Problem creating page in different languages programmatically

Vote:
 

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 9.0.3.0 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?

#144671
Feb 17, 2016 10:51
Vote:
 

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.

#144672
Feb 17, 2016 10:54
Vote:
 

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..)

#144681
Edited, Feb 17, 2016 12:22
Vote:
 

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

#144682
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.