Save page, keep published state

Vote:
 

Hi,

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

Regards,

Emil

#38006
Mar 26, 2010 12:53
Vote:
 

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: http://blog.fredrikhaglund.se/blog/2009/02/18/work-with-unpublished-pagedata-from-code/

 

#38043
Mar 26, 2010 18:22
Vote:
 

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

//Emil

#38048
Mar 26, 2010 22:01