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 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.

Thanks!

share|improve this question

2 Answers 2

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

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfilecollection.add.aspx

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.

share|improve this answer

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();

share|improve this answer
    
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

 
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.