office 365 API with Visual studio 2013 using file REST API RRS feed

  • Question

  • Hi,

    I have an created web application to access files (only .doc files) from VS 2013 using office 365 API,

    but I trying to download the file by use of these below request

    GET ../_api/files(<file_path>)/download

    I am unable to download the file content...

    can anyone help me the other article for download the files or any example code in C#...plz share with me...

    Wednesday, June 11, 2014 5:47 AM

All replies

  • Try  below

    //First construct client context, the object which will be responsible for
        //communication with SharePoint:
        var context = new ClientContext(@"http://site.absolute.url")
        //then get a hold of the list item you want to download, for example
        var list = context.Web.Lists.GetByTitle("Pipeline");
        var query = CamlQuery.CreateAllItemsQuery(10000);
        var result = list.GetItems(query);
        //note that data has not been loaded yet. In order to load the data
        //you need to tell SharePoint client what you want to download:
        context.Load(result, items=>items.Include(
            item => item["Title"],
            item => item["FileRef"]
        //now you get the data
        //here you have list items, but not their content (files). To download file
        //you'll have to do something like this:
        var item = items.First();
        //get the URL of the file you want:
        var fileRef = item["FileRef"];
        //get the file contents:
        FileInformation fileInfo = File.OpenBinaryDirect(context, fileRef.ToString());
        using (var memory = new MemoryStream())
              byte[] buffer = new byte[1024 * 64];
              int nread = 0;
              while ((nread = fileInfo.Stream.Read(buffer, 0, buffer.Length)) > 0)
                  memory.Write(buffer, 0, nread);
              memory.Seek(0, SeekOrigin.Begin);
              // ... here you have the contents of your file in memory, 
              // do whatever you want

    Also check if this helps

    Wednesday, June 11, 2014 6:10 AM
  • Thanks for replied to me, but I would like to download file from office 365 one drive...using office 365 API tool with VS 2013.
    Wednesday, June 11, 2014 9:53 AM
  • Above code is CSOM and will work for Sharepoint online. 

    NOt sure about one drive. may be you can give it a try

    Thursday, June 12, 2014 5:24 AM