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 Sakari H

I am software developer/architect from Finland. Originally I've worked long with SharePoint platform (from SharePoint 2007 to SharePoint 2019 & SharePoint Online), but now more with other things.
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?

    Thanks,

    Saima

    • sakarih says:

      Hi,

      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 comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.