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

我遇到了上传大文件到我的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;

}

回答:

与您的代码段2号的问题是,你错过了一个文件名:

using (var fs = new FileStream(fileInfo.FullName, FileMode.Open)) 

{

Microsoft.SharePoint.Client.File.SaveBinaryDirect(

context,

serverRelativeURL + directory + fs.Name,

^^^^^^^^

fs,

true);

}

回答:

我关于这个主题的研究表明,使用FrontPage Remote Control Procedures是可靠上传大文件的最有效办法。

这是因为FrontPage RPC支持文件碎片,这有助于避免OutOfMemomory异常,因为Windows需要将整个文件分配给连续内存。

它还支持发送元数据,它非常适用于任何文件上传应用程序。这样做的一个主要优点是,您实际上可以指定正确的内容类型,而无需用户登录并稍后进行更改。 (我尝试过的所有其他方法只会设置为默认类型)。

See my answer on the Sharepoint StackExchange有关实现Frontpage RPC的更多详细信息。

以上是 上传>以编程方式将5 MB文件上传到sharepoint 2013 的全部内容, 来源链接: utcz.com/qa/259995.html

回到顶部