Save page, keep published state



A quick question: I want to programmatically save a page and keep the current status. How do I do that in a simple way?



Mar 26, 2010 12:53

You need to check if the current version is published or not using page Status property. Use that to decide what save action to use (Save, CheckIn or Publish). Use ForceCurrentVersion to over write the existing version.

The following example is touching the bits you need even if it is not doing exactly what you want so you can use it as a starting point:

if (page.IsModified)
    SaveAction saveAction = SaveAction.CheckIn;
    if (page.Status != VersionStatus.Published)
        // Update existing version if it is not published
        saveAction = saveAction | SaveAction.ForceCurrentVersion;
    DataFactory.Instance.Save(page, saveAction);

You should also have a look here:


Mar 26, 2010 18:22

Thank you, Fredrik. I was hoping that would be an easier (less verbose) way to accomplish the same thing. I can also tell you that the blog post you referred to has been a life saver on more than one occasion during our current project. Thank you for sharing. :-)


Mar 26, 2010 22:01
* 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.