开发者

Add a document and metadata to a document library without creating 2 versions

I have a requirement to programmatically add a file along with metadata to a document library and in an event handler. I am usin开发者_如何转开发g the following code in the asynchronous “ItemAdded” and “ItemUpdated” events:

SPFile destFile = web.Files.Add(newUrl, newFile, true);

SPListItem destItem;
if (destFile.Item != null)
{
    destItem = destFile.Item;
}
else
{
    destItem = list.Items.Add(folderUrl, SPFileSystemObjectType.File);
}

foreach (DictionaryEntry property in properties)
{
    destItem.Properties[property.Key.ToString()] = property.Value;
}

destItem.Update();

However, each time a file is added, two versions are created, one when the Files.Add method is called and one when the SPListItem.Update method is called. Is there another way to do this where only one version will be created?

Thanks in advance!


Use

destItem.SystemUpdate( false );

in stead of .Update() to avoid creating a new version.


The Add() method has an override which accepts a hashtable to pass metadata along with the file. This way there is no need to call Update() or SystemUpdate() methods.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜