Upload file to SharePoint while setting metadata and checkin comment within 1 version?
From a web form (hosted in SharePoint) i am able to upload a document to a document library. I am also able to set meta data properties and provide the checkin comment.
The problem/question... When i do the above, it is creating 2 versions..one for upload and another when i add the checkin comment.
How can I provide the checkin comment with the metadata all a开发者_Go百科t the same time as uploading the document so that only 1 version exists at the end?
You could use SPListItem.SystemUpdate(false) for update without increment the item version
You can do this with a SPItemEventReceiver in the ItemAdding event. There you can set the metadata in the AfterProperties property of the SPItemEventProperties object, which is passed as parameter of the ItemAdding method.
public class MyEventReceiver : SPItemEventReceiver
{
public override void ItemAdding(SPItemEventProperties properties)
{
properties.AfterProperties["MyMetadataField"] = "Foo";
}
}
The event receiver class can be registered by a Feature or programmatically by the SharePoint object model on the list (SPList.EventReceivers).
SPFile.CheckIn(comments, SPCheckinType.OverwriteCheckIn);
精彩评论