开发者

Upload file to SharePoint while setting metadata and checkin comment within 1 version?

开发者 https://www.devze.com 2023-04-12 20:45 出处:网络
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.

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);

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号