Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a job that runs every five minutes and puts some information to the footer of the Word documents. Versioning is enabled on the list so whenever the job runs, a new version is created for every document.

Is there a way to modify the documents without creating new versions every time?

Currently, I am reading the file contents with SPFile.OpenBinary(), modifying the stream, then putting the file back with file.ParentFolder.Files.Add(fileName, stream).

Any help is greatly appreciated.

share|improve this question
add comment

3 Answers

up vote 2 down vote accepted

You can call SystemUpdate(false) method to update the item without incrementing the version number. More information here: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splistitem.systemupdate.aspx

share|improve this answer
    
But I am not updating the item. I am not calling item.Update() anywhere. Just pulling the binary stream then putting it back as I wrote in my question. –  Élodie Petit Dec 4 '11 at 14:16
    
When you call add method, a new file is upload and if file name is same a new version is created. I am not sure you can avoid a new version in that case. –  Ashish Patel Dec 4 '11 at 14:32
    
So, is there any way for modifying the contents of the file other that requires adding file to parent file collection? –  Élodie Petit Dec 5 '11 at 7:39
    
The File itself exists as special kind of attachment in the ListItem. If you modify the file you must call Update(). If you don't want a new version created, you must call SystemUpdate(false). Test this out and see if it still creates a new version. –  James Love Dec 5 '11 at 13:46
    
I am not working on the list item. I get the item, open it's attachment by calling item.File.OpenBinaryStream(). So item itself is not updated anywhere. When I am finished working on the file, I put it back to file collection of parent folder. So I am not calling listItem.Update() or listItem.SystemUpdate(). Those calls are not needed in my case. But a new version is automatically created when I put the file in parent folder. –  Élodie Petit Dec 6 '11 at 12:16
add comment

All of your posts helped me build a solution.

We are using the Client Object Model (COM) and cannot refer to SharePoint.dll which has the SPList object. In our given scope of COM, I could accomplish it by doing this in the C# code.

  1. Load the File and check out

            clientContext.Load(file);
            file.CheckOut(); // Check out the File
            clientContext.ExecuteQuery();
    
  2. Update our file properties as follows:

            file.ListItemAllFields["Owner"] = "Owner Name";
            file.ListItemAllFields["Field"] = "Value";
    
  3. Finally Update the List Item and Check in the file as shown below

            file.ListItemAllFields.Update(); // Update the Properties
            // Checkin the file with Overwrite to maintain the version
            file.CheckIn(string.Empty, CheckinType.OverwriteCheckIn); 
            clientContext.ExecuteQuery();
    

Hope this helps some one.

share|improve this answer
    
Ravi, is this answer related to the question above? I am not sure if you answered the correct question. –  Kit Menke Jun 19 '12 at 22:03
add comment

If you don't want to keep the version, it seems you no longer need the unmodified file. You can delete(SPFileCollection.Delete) the file and add the modified one after that.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.