tags:

views:

215

answers:

1

Each version can be given a comment when it is edited in the browser and this can be seen when viewing an items versions in in the browser.

When I programmatically change a fields value on an SPListItem I would like to set a comment for this change. Ideally the comment string would be passed as a parameter to SPListItem.Update but it doesn't have any parameters. Nor can I find a property on the SPListItem to set this.

If I overwrite a file in a document library using SPFileCollection.Add then there's a parameter available to set the checkInComment which is exactly what I want, but I can't find it on an SPListItem.

What I'm trying to update is the metadata on a document in a document library. As above I can add version comments when I overwrite with newer versions of the document, just not when I overwrite the fields themselfs.

+3  A: 

The check-in comments are controlled by the SPFile class, not SPListItem. SPFile.CheckIn() and SPFile.Publish() both take string parameters to set the comment. You can't overwrite a previous check-in comment (the CheckInComment property of SPFile is read-only), so in your code you will want to do something like

SPFile myFile;
//Retrieve File
myFile.CheckOut();
SPListItem fileItem = myFile.Item;
Item["someField"] = "New Value";
.
.
.
fileItem.Update();
myFile.CheckIn("My comments are here.");
myFile.Update();
OedipusPrime
Tested and it works. Thankyou :)
Dan Revell