Cannot save or change unpubllished page


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);
  repository.Save(content: epiWhitePage, action: SaveAction.CheckIn, access: EPiServer.Security.AccessLevel.NoAccess);

Feb 13, 2014 21:46

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.

Feb 17, 2014 18:14

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.

Feb 17, 2014 19:25

I have figured this out. You have to call LoadCommonDraft. if it returns a draft, you must save it as "SaveAction.Reject", then call LoadCommonDraft again and save as "SaveAction.CheckIn".

Feb 17, 2014 20:09
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.