Multiple versions of a document added on each update
-
I have a project that has a piece that uploads documents to a library in which versioning is turned on. Everytime I add a new document or update a document I get two versions per update call. Here is my code:
'create the spfile item
Dim twoXtwoFile As SPFile = twoXtwo.RootFolder.Files.Add(fileName, fileBytes, True)
Dim twoXtwoItem As SPListItem = twoXtwoFile.Item
twoXtwoItem(twoXtwos.Year) = year
twoXtwoItem("Title") = fileName
twoXtwoItem(twoXtwos.Executive) = New SPFieldLookupValue(CInt(Request.QueryString("ID")), execItem(Execs.LookupName).ToString)Try twoXtwoItem.Update() Catch ex As Exception 'display an error message errorMessage.InnerText = "Sorry, but this file could not be added. Please try again or contact the IT Department Help Desk." Finally web.Dispose() End Try
The code runs fine, but when I go look at the version history of the document you can see where you have two versions that are the exact same. You really notice on the first upload where you have version 1.0, which is the file itself, and then version 2 that has the same file and the list column items added to it. All subsequent updates just contain two versions of the same update. The only thing I can think of here is that my code is updating the file first and then going back and adding the list values to the object. Am I right to think that and what can I do so that I only have one version per update/add?
-
I have a project that has a piece that uploads documents to a library in which versioning is turned on. Everytime I add a new document or update a document I get two versions per update call. Here is my code:
'create the spfile item
Dim twoXtwoFile As SPFile = twoXtwo.RootFolder.Files.Add(fileName, fileBytes, True)
Dim twoXtwoItem As SPListItem = twoXtwoFile.Item
twoXtwoItem(twoXtwos.Year) = year
twoXtwoItem("Title") = fileName
twoXtwoItem(twoXtwos.Executive) = New SPFieldLookupValue(CInt(Request.QueryString("ID")), execItem(Execs.LookupName).ToString)Try twoXtwoItem.Update() Catch ex As Exception 'display an error message errorMessage.InnerText = "Sorry, but this file could not be added. Please try again or contact the IT Department Help Desk." Finally web.Dispose() End Try
The code runs fine, but when I go look at the version history of the document you can see where you have two versions that are the exact same. You really notice on the first upload where you have version 1.0, which is the file itself, and then version 2 that has the same file and the list column items added to it. All subsequent updates just contain two versions of the same update. The only thing I can think of here is that my code is updating the file first and then going back and adding the list values to the object. Am I right to think that and what can I do so that I only have one version per update/add?
Well, as I see it, you add the file. That is one version. Then you take the file, change it values and update them. That's the second version. Perhaps it would be a better way, to create the Item and add the file to it, change the properties and the add it to the list. I didn't tried it yet, so it may be wrong, but I think I did it once in that way.
Author of Primary ROleplaying SysTem How do I take my coffee? Black as midnight on a moonless night. War doesn't determine who's right. War determines who's left.