Prevent page from being changed when I save and publish it programmatically

Member since: 2010

Hi, guys,

How can I prevent page from being changed when I save and publish it programmatically?

Basically, I would like to prevent that ChangedBy and Changed are changed when I add items to a specific content area programmatically.

Thx a lot!


#114544 Dec 15, 2014 11:51
  • Member since: 2009

    Does the ForceCurrentVersion flag update those values?

    #114545 Dec 15, 2014 12:17
  • Member since: 2010

    Not sure, let me give it a try

    #114547 Dec 15, 2014 12:19
  • Member since: 2010

    I have to use ForceCurrentVersion  with Publish, otherwise the page doesn't get published at all. This does change the username, but I'll give it some more debugging to make sure I've tried out everything.

    #114567 Dec 15, 2014 16:12
  • Member since: 2009

    If the page is not already published, and you need to do that, perhaps you could try manually setting the properties for Status, perhaps check IsPendingPublished and also StartPublish.  ForceCurrentVersion will not clear the cache, so you'll probably need to do that as well.

    #114593 Dec 16, 2014 10:08
  • Member since: 2010

    Hey, Per, thx a lot for your help, this combination worked: SaveAction.CheckIn | SaveAction.ForceCurrentVersion:

    contentRepo.Save(clone, SaveAction.CheckIn | SaveAction.ForceCurrentVersion, AccessLevel.NoAccess);


    #114825 Dec 23, 2014 13:55
  • This message was deleted by marryxiao marryxiao at Dec 24, 2014 12:38.
  • Member since: 2010

    I've added the following blog post on the subject:

    #117889 Feb 23, 2015 16:48
  • Member since: 2009


    thanks for sharing that! There might be a way around the "ChangedBy" though. Have you tried something like this?

                var clone = somePage.CreateWritableClone();
                // create a temporary principal with the same name as the current "changedBy" value
                PrincipalInfo.CurrentPrincipal = new GenericPrincipal(new GenericIdentity(somePage.ChangedBy),null);
                // modfiy stuff 
                clone.PageName = "My new name";
                // .. and save
                contentRepository.Save(clone, SaveAction.Publish, AccessLevel.NoAccess);

    #117892 Feb 23, 2015 17:54
  • Member since: 2010

    I have thought about it, but it looked dirty. Then I would need to reset back the current principal. Then in future, if someone else gets hold of the code and wraps the actual principal in an if statement, here go the website autorization, everybody gets manager's access rights :D Paranoid or realistic?

    #117893 Feb 23, 2015 18:14
  • Member since: 2009

    Maybe a little bit of both? :-)

    I guess it's not the safest bit of code, but if done right it I wouldn't be too worried. Well.. Until someone else gets hold of the code as you say. 
    This blogpost shows a rather clean way of temporary using another principal. Use at own risk I suppose

    #117907 Feb 24, 2015 8:38
First   1 2   Last