November Happy Hour will be moved to Thursday December 5th.
AI OnAI Off
November Happy Hour will be moved to Thursday December 5th.
I wanted to add an update. I have found that when the page is saved with this code, it creates a new version but does not recognize any changes.
Is the issue because of the repository I'm getting the page from? I've tried casting draftPage to MyPage but can't figure out how to cast a ContentVersion to MyPage.
One more update. I have found that if I publish the previous unpublished page then I can make changes and save a new unpulished page. This seems really wrong. It's forcing us to publish chnages we don't want published.
If use the following code to return the most recent version of a page and make some edits my custome properties. The issue is that epiWhitePage.MyText = "My New Text" never gets saved. I was able to save it once before there was an unpublished version. Now I can't make updates to the unpublished version.
var repository = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<IContentRepository>();
ContentVersion draftPage = draftRepository.LoadCommonDraft(contentLink: MyPageContentLink, language: Language.Name);
MyPage epiWhitePage = (MyPage)repository.Get<MyPage>(contentLink: draftPage.ContentLink,
selector: LanguageSelector.AutoDetect(true)).CreateWritableClone();
bool isDraft = (draftPage.IsCommonDraft && draftPage.Status == VersionStatus.CheckedIn);
epiWhitePage.MyText = "My New Text"
if (isDraft)
{
repository.Save(content: epiWhitePage, action: SaveAction.ForceCurrentVersion, access: EPiServer.Security.AccessLevel.NoAccess);
}
else
{
repository.Save(content: epiWhitePage, action: SaveAction.CheckIn, access: EPiServer.Security.AccessLevel.NoAccess);
}