0

我正在Visual Studio 中开发SharePoint Office 365 应用程序。我使用 FileUpload 控件通过 CSOM 将文件上传到 SharePoint 文档库。

我面临一个问题。SharePoint Office 365 应用程序不允许在我的自定义页面中上传大于 3 MP 的文件并显示以下错误消息。

Maximum request length exceeded.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Maximum request length exceeded.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[HttpException (0x80004005): Maximum request length exceeded.]
   System.Web.HttpRequest.GetEntireRawContent() +9726860
   System.Web.HttpRequest.GetMultipartContent() +63
   System.Web.HttpRequest.FillInFormCollection() +165
   System.Web.HttpRequest.EnsureForm() +75
   System.Web.HttpRequest.get_Form() +12
   System.Web.HttpRequest.get_HasForm() +9728411
   System.Web.UI.Page.GetCollectionBasedOnMethod(Boolean dontReturnNull) +95
   System.Web.UI.Page.DeterminePostBackMode() +69
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +130

请帮助我,如何增加 SharePoint 应用程序中文件上传的最大大小。

提前致谢。

4

2 回答 2

1

以下示例演示如何使用File.SaveBinaryDirect 方法将文件上传到 O365 :

public static void UploadFile(Web web,string serverRelativeUrl, string filePath)
{
     using (var fs = new FileStream(filePath, FileMode.Open))
     {
        var fi = new FileInfo(filePath);
        var fileUrl =  String.Format("{0}/{1}", serverRelativeUrl, fi.Name);
        Microsoft.SharePoint.Client.File.SaveBinaryDirect(ctx, fileUrl, fs, true);
     }
} 

用法

//Upload file into Assets library
UploadFile(ctx, "/Assets", @"C:\VideoArchive\VideoSample.mp4");

上传大小超过 3MB 的文件时它适用于我

如何更新文件属性

//Update Title property for File object
var uploadedFile = ctx.Web.GetFileByServerRelativeUrl(fileRelativeUrl);
uploadedFile.ListItemAllFields["Title"] = "New Title";
uploadedFile.ListItemAllFields.Update();
ctx.ExecuteQuery();
于 2014-06-12T10:06:41.083 回答
0
 using (ClientContext context = TokenHelper.GetClientContextWithAccessToken(Request.QueryString["SPHostUrl"].ToString(), accessToken))
                {
                    //Get Web and List object
                    Web web = context.Site.OpenWeb("test");
                    List list = web.Lists.GetByTitle("Documents");
                    //Open file
                    System.IO.FileStream stream = System.IO.File.OpenRead(txtFilePath.Text);
                    //Create new file creation info object        
                    FileCreationInformation fileCreation = new FileCreationInformation();
                    fileCreation.ContentStream = stream;
                    fileCreation.Overwrite = true;
                    fileCreation.Url = "test";
                    //Add File to documents library
                    File uploadedFile = list.RootFolder.Files.Add(fileCreation);
                    list.Update();
                    web.Update();
                    context.ExecuteQuery();
                }

试试这个解决方案来上传文件。

于 2014-06-12T08:53:40.037 回答