2013-02-25 78 views
1

我正在使用CSOM将文件上传到Sharepoint 365网站。上传大文件到Sharepoint 365

我已经登录成功地使用基于声明的身份验证在这里找到方法“http://www.wictorwilen.se/Post/How-to-do-active-authentication-to-Office-365-and-SharePoint-Online.aspx

但使用SaveBinaryDirect在ClientContext失败,405由于饼干被连接到请求为时已晚。

使用CSOM上传文件的另一种方法与以下类似。但是对于SP 365,这会将文件大小限制在3 meg左右。

var newFileFromComputer = new FileCreationInformation 
       { 
        Content = fileContents, 
        Url = Path.GetFileName(sourceUrl) 
       }; 


Microsoft.SharePoint.Client.File uploadedFile = customerFolder.Files.Add(newFileFromComputer); 
        context.Load(uploadedFile); 
        context.ExecuteQuery(); 

有没有办法做到这一点使用CSOM,SP 365和文件大小可以说100兆?

回答

1

那么,我还没有找到一种方法来处理CSOM,这真是令人生气。

SEvans在http://www.wictorwilen.se/Post/How-to-do-active-authentication-to-Office-365-and-SharePoint-Online.aspx的评论中发布了解决方法。

基本上只是做一个http放,并从基于声明的身份验证附加cookie集合。 SEvans公布的解决方法是低于


伟大的代码Wichtor。正如其他人所指出的那样,SaveBinaryDirect无法正常工作,因为FedAuth cookie从未附加到该方法生成的HTTP PUT请求。

这里是我的解决方法 - 希望这有助于一些你:

// "url" is the full destination path (including filename, i.e. https://mysite.sharepoint.com/Documents/Test.txt) 

// "cookie" is the CookieContainer generated from Wichtor's code 
// "data" is the byte array containing the files contents (used a FileStream to load) 

System.Net.ServicePointManager.Expect100Continue = false; 
HttpWebRequest request = HttpWebRequest.Create(url) as HttpWebRequest; 
request.Method = "PUT"; 
request.Accept = "*/*"; 
request.ContentType = "multipart/form-data; charset=utf-8"; 
request.CookieContainer = cookie; request.AllowAutoRedirect = false; 
request.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)"; 
request.Headers.Add("Accept-Language", "en-us"); 
request.Headers.Add("Translate", "F"); request.Headers.Add("Cache-Control", "no-cache"); request.ContentLength = data.Length; 

using (Stream req = request.GetRequestStream()) 
{ req.Write(data, 0, data.Length); } 

HttpWebResponse response = (HttpWebResponse)request.GetResponse(); 
Stream res = response.GetResponseStream(); 
StreamReader rdr = new StreamReader(res); 
string rawResponse = rdr.ReadToEnd(); 
response.Close(); 
rdr.Close(); 
+0

根据微软还应该增加一个X-HTTP-法头“PUT”的值http://msdn.microsoft.com /en-us/library/ff798339.aspx – 2014-03-23 17:05:40