0

i have one question. How do pro-grammatically store the sharepoint document library document(eg Image.png) to local machine(D:/Images)?? Anybody have a solution???

1 Answer 1

1

Something like:

var context = new ClientContext("http://sp2010app");
var web = context.Web;
var list = web.Lists.GetByTitle("Shared Documents");
var items = list.GetItems(CamlQuery.CreateAllItemsQuery());
context.Load(items);
context.ExecuteQuery();
foreach (var item in items)
{
    var stream = Microsoft.SharePoint.Client.File.OpenBinaryDirect(context, (string)item["FileRef"]).Stream;
    var filename = string.Format("d:\\images\\{0}", item["FileLeafRef"]);
    using (Stream file = System.IO.File.OpenWrite(filename))
    {
        stream.CopyTo(file);
    }
}
2
  • error:"System.IO.Stream does not contain the definition for 'CopyTo' and no extension method 'CopyTo' accepting a first argument type of System.IO.Stream could be found"
    – Sakthi
    Aug 22, 2013 at 10:01
  • CopyTo requires .Net 4, if you're using earlier version then see How do I save a stream to a file? Aug 22, 2013 at 10:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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