I use the SaveBinary() method of the SPFile class to save the new file to an existing document library item. The problem is, if this document library item is an Office document, the SaveBinary() method will clear all the custom fields (columns) of this document library item and it will set back the item to its default content type). Doesn't happen with a text-based file.

Any help would be greatly appreciated.



Try using SPFileCollection.Add(...) instead.


If you have a list, you can get the root folder and call folder.Files.Add(...)

If you have a URL, you can get the folder using the SPWeb and then doing the same.

Add(...) allows you to specify a byte[] with the binary contents of the file and a hashtable with metadata to provide to the list item.

There is a Boolean parameter that you can set to true to cause it to overwrite an existing document. This should create a version as well.

Also consider patching your SharePoint environment. I noticed this behavior with earlier versions of 2007, but not with later patches.


Not really sure but try this

After you call the myItem.File.SaveBinary(fs) and call myItem.File.Update(), again create a new list item object newmyItem refering to the same item you updated above and call newmyItem.Update();

  • Read somewhere its about ParserEnabled = False, but not much of a solution for me (some saying put it to false, update, then put it to true), im not sure what will happen when multiple users are doing the same job, any idea? – Zee99 Sep 17 '10 at 14:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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