I am using Sharepoint 2010. I am programmatically adding documents to a document library (inside of a timer job). The core code to do this is:
SPFileCollection libFileCol = library.RootFolder.Files; SPFile spFile = libFileCol.Add(library.RootFolder.Url + "/" + (new FileInfo(docPath).Name), fileContent, true, docComment, false); SPListItem newItem = library.GetItemById(spFile.ListItemAllFields.ID); SPContenttype documentContentType = library.ContentTypes["Document"]; newItem["ContentTypeId"] = documentContentType.Id; newItem["Title"] = "my title";
newItem["Created"] = "32";
newItem["Modified"] = "32";
newItem.Update();
This seems to work as the item is added to the document library. The problem I am seeing, however, is when I view the version history. When I view the history, I see two items. Version 1.0 is owned by 'System Account' and version 2.0 is owned by the user I set via the created/modified metadata. It seems like the 1.0 version is added when the document is initially added to the library and the version 2.0 is added on the newItem.Update().
Does anyone know why this is happening and if it can be corrected to only reflect the one version.
Thanks - Peter