SharePoint Office 365应用程序,增加文件上载大小

时间:2014-06-12 08:34:03

标签: c# sharepoint sharepoint-apps

我正在开发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 Apps中增加文件上传的最大大小。

提前致谢。

2 个答案:

答案 0 :(得分:1)

以下示例演示了如何使用File.SaveBinaryDirect method将文件上传到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();

答案 1 :(得分: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();
                }

尝试使用此解决方案上传文件。

相关问题