SharePoint 2007: SPListItem.File.Publish() locks down splistitem


Okay quiet but not sleeping… Recently I have been puzzled with this kind of thingy. If you programmatically publish a SharePoint listitem, you’ll get problems in Workflow and more specially at that point if you try to do SPListItem.update() thing. Apparently SharePoint 2007 locks down SPListItem after SPFile.Publish() has been ran.

Now this locking is a bit of odd since after returning from a workflow to back SharePoint, you can do anything to that document but if you try directly after calling that Publish() method you’ll get error saying that “xxx has modified item” or something like that. (Sorry using Finnish WSS 3.0 so errors do come in Finnish, nice thing but sooo much problems when you try to search solutions to those errors….)

So now you might wonder why this is a problem or why in earth I am writing this. Okay consider this scenario: you have a custom made Workflow (Visual Studio style) that copies your splistitem into another location. Then you (or somebody else) wants it to put Version History as a published item. So then you figure (or argue that never going to do this) out how to stamp splistitem as published. Okay then you hit this nice little thingy called SPListItem.SPFile.Publish(). So no problem… After a while you’ll figure out that you need to save some custom information after this publish has been hitten (let’s say that you want to capture the timestamp of this publish call). So next brilliant though is to put this as a column with this item. So now you are getting your feet wet and hitting the drainage sewer.

Feel free to test this or even better, tell me is this “normal” SharePoint behaviour and is there a way to write SPListItem stuff directly after .Publish() –method in a way that it creates a new version of the splistitem instantly.


About Sakarih

I am SharePoint developer/architect from Finland and my blogposts are all about SharePoint 2007/2010/2013 stuff. There might be also something else posted.
This entry was posted in Uncategorized. Bookmark the permalink.

2 Responses to SharePoint 2007: SPListItem.File.Publish() locks down splistitem

  1. Saima says:

    Hi did you get to the bottom of this? i’m trying to retain the original createdby and modified user, however the publish() changes this to the user running the script (admin) – how can i either update the user after publish or force the publish method to use the original user?



    • sakarih says:


      Sorry for the huge delay. I just modified the logic so that this does not cause further problems. Althought there might be something within the workflow that this could be voided (like adding delays etc).

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s