How to download/upload files from/to SharePoint 2013 using CSOM?

后端 未结 8 2142
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-30 20:19

I am developing a Win8 (WinRT, C#, XAML) client application (CSOM) that needs to download/upload files from/to SharePoint 2013.

How do I do the Download/Upload?

8条回答
  •  伪装坚强ぢ
    2020-11-30 20:49

    File.OpenBinaryDirect may cause exception when you are using Oauth accestoken Explained in This Article

    Code should be written as below to avoid exceptions

     Uri filename = new Uri(filepath);
            string server = filename.AbsoluteUri.Replace(filename.AbsolutePath, 
             "");
            string serverrelative = filename.AbsolutePath;
    
            Microsoft.SharePoint.Client.File file = 
            this.ClientContext.Web.GetFileByServerRelativeUrl(serverrelative);
            this.ClientContext.Load(file);
            ClientResult streamResult = file.OpenBinaryStream();
            this.ClientContext.ExecuteQuery();
            return streamResult.Value;
    

提交回复
热议问题