I would like to use this method to get the byte information from a document based on its URL so that I can copy it to a new location. I have only seen examples using file.OpenBinary(); where file is simply used within a foreach loop through all the files in a library. I have a list that I use as a sort of "queue" which adds an item with its source url in one column and the destination url in another. How can I essentially do something like:

file = "mysite.com/file2.docx"
byte[] myFile = file.OpenBinary();
SPFile copiedFile = someLibrary.Add(System.IO.Path.GetFileName(file.Url), myFile);

Is this possible?


You can use SPWeb.GetFile method to get the SPFile object from string URL.

Then you can use SPFile.OpenBinary method and so on..

Of course you will need SPWeb object of the site where the file exists..

| improve this answer | |

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.