• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

上传>以编程方式将5 MB文件上传到sharepoint 2013

c/c++ 来源:B-M 4次浏览

我遇到了上传大文件到我的SharePoint 2013/Office 365站点的麻烦。我使用Visual Stuidos 2010和.NET 4.0上传>以编程方式将5 MB文件上传到sharepoint 2013

我曾尝试代码这些问题:

SP2010 Client Object Model 3 MB limit – updating maxReceivedMessageSize doesnt get applied

maximum file upload size in sharepoint

Upload large files 100mb+ to Sharepoint 2010 via c# Web Service

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

但没有什么工作。所以我需要一点帮助。下面是我曾尝试代码:

1:(I也试图使用SharePointOnlineCredentials代替NetworkCredential为这一个)

#region 403 forbidden 

byte[] content = System.IO.File.ReadAllBytes(fileInfo.FullName); 
System.Net.WebClient webclient = new System.Net.WebClient(); 
System.Uri uri = new Uri(sharePointSite + directory + fileInfo.Name); 
webclient.Credentials = new NetworkCredential(user, password.ToString(), sharePointSite + "Documents"); 

webclient.UploadData(uri, "PUT", content); 

#endregion 

2:

#region 500 Internal Server Error 


using (var fs = new FileStream(fileInfo.FullName, FileMode.Open)) 
{ 
    Microsoft.SharePoint.Client.File.SaveBinaryDirect(
     context, 
     web.ServerRelativeUrl + "/" + directory, 
     fs, 
     true); 
} 

#endregion 

我已经得到了更小的文件上传使用:

#region File upload for smaller files 

Folder folder = context.Web.GetFolderByServerRelativeUrl(web.ServerRelativeUrl + directory); 
web.Context.Load(folder); 
context.ExecuteQuery(); 

FileCreationInformation fci = new FileCreationInformation(); 

fci.Content = System.IO.File.ReadAllBytes(fileInfo.FullName); 

fciURL = sharePointSite + directory; 
fciURL += (fciURL[fciURL.Length - 1] == '/') ? fileInfo.Name : "/" + fileInfo.Name; 

fci.Url = fciURL; 
fci.Overwrite = true; 

Microsoft.SharePoint.Client.FileCollection documentfiles = folder.Files; 
context.Load(documentfiles); 
context.ExecuteQuery(); 

Microsoft.SharePoint.Client.File file = documentfiles.Add(fci); 
context.Load(file); 
context.ExecuteQuery(); 

#endregion 

我的使用声明:

using (Microsoft.SharePoint.Client.ClientContext context = new Microsoft.SharePoint.Client.ClientContext(sharePointSite)) 
{ 
    //string fciURL = ""; 
    exception = ""; 
    context.Credentials = new Microsoft.SharePoint.Client.SharePointOnlineCredentials(user, password); 


    Web web = context.Web; 
    web.Context.Credentials = context.Credentials; 


    if (!web.IsPropertyAvailable("ServerRelativeUrl")) 
    { 
     web.Context.Load(web, w => w.ServerRelativeUrl); 
     web.Context.ExecuteQuery(); 
    } 

    //upload large file 
} 

===========解决方案如下:

我去解决办法:

MemoryStream destStream; 

using (System.IO.FileStream fInfo = new FileStream(fileInfo.FullName, FileMode.Open)) 
{ 

    byte[] buffer = new byte[16 * 1024]; 
    byte[] byteArr; 

    using (MemoryStream ms = new MemoryStream()) 
    { 
     int read; 
     while ((read = fInfo.Read(buffer, 0, buffer.Length)) > 0) 
     { 
      ms.Write(buffer, 0, read); 
     } 
     byteArr = ms.ToArray(); 
    } 

    destStream = new MemoryStream(byteArr); 

    Microsoft.SharePoint.Client.File.SaveBinaryDirect(
     context, 
     serverRelativeURL + directory + fileInfo.Name, 
     destStream, 
     true); 

    context.ExecuteQuery(); 
    results = "File Uploaded"; 
    return true; 
} 

版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)