我正尝试从代码中将500 MB-2GB范围内的大文件(大于256MB)上传到sharepoint Server 2013,但没有找到一种方法。我成功手动上传了大小约为1GB的大文件。
我尝试过following MSDN examples ,它仅适用于<256 MB的文件。
根据this post (at the buttom):“ ...块上传仅在SharePoint Online和SharePoint 2016 OnPremise中可用,在SharePoint 2013 OnPremise中不可用。”
我的问题是如何将大文件上传到Sharepoint Server 2013?
答案 0 :(得分:0)
可以使用SaveBinaryDirect选项在SharePoint 2013 Server中上传大文件:
public void SaveBinaryDirect(ClientContext ctx, string libraryName, string filePath)
{
Web web = ctx.Web;
// Ensure that target library exists, create if is missing
if (!LibraryExists(ctx, web, libraryName))
{
CreateLibrary(ctx, web, libraryName);
}
List docs = ctx.Web.Lists.GetByTitle(libraryName);
ctx.Load(docs, l => l.RootFolder);
// Get the information about the folder that will hold the file
ctx.Load(docs.RootFolder, f => f.ServerRelativeUrl);
ctx.ExecuteQuery();
using (FileStream fs = new FileStream(filePath, FileMode.Open))
{
Microsoft.SharePoint.Client.File.SaveBinaryDirect(ctx, string.Format("{0}/{1}", docs.RootFolder.ServerRelativeUrl, System.IO.Path.GetFileName(filePath)), fs, true);
}
}
参考: