Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. SharePoint
  4. Multiple versions of a document added on each update

Multiple versions of a document added on each update

Scheduled Pinned Locked Moved SharePoint
helpannouncementquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Aptiva Dave
    wrote on last edited by
    #1

    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 1 Reply Last reply
    0
    • A Aptiva Dave

      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 Offline
      I Offline
      Ingo
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups