在嘗試上傳文件到SharePoint聯機時,通過SharePointClient
upload
遠程上傳文件時,遇到的文件大小限制爲2mb。在我的搜索中,似乎人們已經用PowerShell
來克服這個限制,但是有沒有辦法在.Net C#中使用原生SharePointClient
包來克服這個限制?這裏是我現有的代碼示例:SharePoint Online,使用SharePointClient上傳超過2mb的文件
using (var ctx = new Microsoft.SharePoint.Client.ClientContext(httpUrl))
{
ctx.Credentials = new Microsoft.SharePoint.Client.SharePointOnlineCredentials(username, passWord);
try
{
string uploadFilename = string.Format(@"{0}.{1}", string.IsNullOrWhiteSpace(filename) ? submissionId : filename, formatExtension);
logger.Info(string.Format("SharePoint uploading: {0}", uploadFilename));
new SharePointClient().Upload(ctx, sharePointDirectoryPath, uploadFilename, formatData);
}
}
我從下面的網站,你可以使用ContentStream只是不知道如何映射到SharePointClient
(如果有的話)閱讀:
https://msdn.microsoft.com/en-us/pnp_articles/upload-large-files-sample-app-for-sharepoint
UPDATE:
每建議的解決方案我現在有:
public void UploadDocumentContentStream(ClientContext ctx, string libraryName, string filePath)
{
Web web = ctx.Web;
using (FileStream fs = new FileStream(filePath, FileMode.Open))
{
FileCreationInformation flciNewFile = new FileCreationInformation();
// This is the key difference for the first case - using ContentStream property
flciNewFile.ContentStream = fs;
flciNewFile.Url = System.IO.Path.GetFileName(filePath);
flciNewFile.Overwrite = true;
List docs = web.Lists.GetByTitle(libraryName);
Microsoft.SharePoint.Client.File uploadFile = docs.RootFolder.Files.Add(flciNewFile);
ctx.Load(uploadFile);
ctx.ExecuteQuery();
}
}
仍然不能正常工作,但會在成功時再次更新。當前錯誤是:
Could not find file 'F:approot12-09-2017.zip'.
FINALLY
我正在使用的文件從Amazon S3這樣的解決辦法是把我的字節數據和流式傳輸到呼叫:
public void UploadDocumentContentStream(ClientContext ctx, string libraryName, string filename, byte[] data)
{
Web web = ctx.Web;
FileCreationInformation flciNewFile = new FileCreationInformation();
flciNewFile.ContentStream = new MemoryStream(data); ;
flciNewFile.Url = filename;
flciNewFile.Overwrite = true;
List docs = web.Lists.GetByTitle(libraryName);
Microsoft.SharePoint.Client.File uploadFile = docs.RootFolder.Files.Add(flciNewFile);
ctx.Load(uploadFile);
ctx.ExecuteQuery();
}
謝謝!我明天會試一試,讓你知道它是如何發展的。 –
有一點需要記住,30分鐘後用這種方法發生超時。微軟的指導是使用文件流上傳文件高達10MB,但你可以逃避更多。如果您仍然遇到問題,請告知我,我將爲「開始」,「繼續」,「完成」上傳方法提供一個示例。 – groveale
嗨,所以我已經嘗試了你建議的稍微修改過的版本。請參閱上面的更新。但是,我從SharePoint中看到以下錯誤:SharePoint錯誤:找不到文件'F:approot12-09-2017.zip'。我上傳的文件是「12-09-2017.zip」。 「F:approot」從哪裏來? –