Adding 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 the document library and the event handler. I use the following code in the asynchronous events "ItemAdded" and "ItemUpdated":

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 File.Add method is called, and one when the SPListItem.Update method is called. Is there any other way to do this when only one version is created?

Thanks in advance!

+4
source share
2 answers

Use

 destItem.SystemUpdate( false ); 

instead of .Update () to avoid creating a new version.

+8
source

The Add () method has an override that accepts a hash table for transferring metadata along with the file. Thus, there is no need to call the Update () or SystemUpdate () methods.

+2
source

All Articles