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!
source share