2016-09-13 12 views
0

管理対象クライアントオブジェクトモデルを使用して、SharePoint 2013のドキュメントライブラリにアップロードするファイルを作成しました。 は、ここに私のupload.aspx共有ポイント2013の管理クライアントオブジェクトモデルを使用してファイルをアップロード

 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication7.WebForm1" %> 

<!DOCTYPE html> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 
</head> 
<body> 
    <form id="form1" runat="server"> 

     <div> 

      <table> 

       <tr> 

        <td colspan="2" align="center"> 

         <asp:Label Font-Bold="true" Text="Upload a documents to SharePoint 2013" runat="server" ID="lblSharePoint" /> 

        </td> 

       </tr> 

       <tr> 

        <td></td> 

       </tr> 

       <tr> 

        <td> 

         <asp:Label ID="lblLocalPath" runat="server" Text="Local Path:"></asp:Label> 

        </td> 

        <td> 

         <asp:FileUpload ID="FileLocalPath" Width="350" runat="server" /> 

        </td> 

       </tr> 

       <tr> 

        <td> 

         <asp:Label ID="lblSharePointURL" runat="server" Text="SharePoint Site URL:"></asp:Label> 

        </td> 

        <td> 

         <asp:TextBox ID="txtSharePointURL" Width="350" runat="server"></asp:TextBox> 

        </td> 

       </tr> 

       <tr> 

        <td> 

         <asp:Label ID="lblLibraryName" runat="server" Text="Library Name:"></asp:Label> 

        </td> 

        <td> 

         <asp:TextBox ID="txtLibraryName" Width="350" runat="server"></asp:TextBox> 

        </td> 

       </tr> 

       <tr> 

        <td colspan="2" align="right"> 

         <asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="btnUpload_Click" /> 

        </td> 

       </tr> 

       <tr> 

        <td colspan="2"> 

         <asp:Label ID="lblMsg" runat="server" Text=""></asp:Label> 

        </td> 

       </tr> 

      </table> 

     </div> 

    </form> 
</body> 
</html> 

され、ここで私は小さなファイルをアップロードしていたときに、私は大きなファイルをアップロードするとき、私のupload.aspx.cs

using Microsoft.SharePoint.Client; 
using System; 
using System.Collections.Generic; 
using System.Drawing; 
using System.IO; 
using System.Linq; 
using System.Net; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 

namespace WebApplication7 
{ 
    public partial class WebForm1 : System.Web.UI.Page 
    { 

     protected void Page_Load(object sender, EventArgs e) 
     { 

     } 

     public ClientContext SPClientContext { get; set; } 

     public Web SPWeb { get; set; } 

     public string SPErrorMsg { get; set; } 

     protected void btnUpload_Click(object sender, EventArgs e) 

     { 
      try 
      { 


       string sURL = txtSharePointURL.Text; 

       string sDocName = string.Empty; 

       if (!string.IsNullOrWhiteSpace(sURL) && !string.IsNullOrWhiteSpace(txtLibraryName.Text) && (FileLocalPath.HasFile)) 
       { 

        bool bbConnected = Connect(sURL, "abhishekr", "A123bhishek", "saras"); 

        if (bbConnected) 
        { 

         Uri uri = new Uri(sURL); 

         string sSPSiteRelativeURL = uri.AbsolutePath; 

         sDocName = UploadFile(FileLocalPath.FileContent, FileLocalPath.FileName, sSPSiteRelativeURL, txtLibraryName.Text); 

         if (!string.IsNullOrWhiteSpace(sDocName)) 
         { 

          lblMsg.Text = "The document " + sDocName + " has been uploaded successfully.."; 

          lblMsg.ForeColor = Color.Blue; 

         } 

         else 
         { 

          lblMsg.Text = SPErrorMsg; 

          lblMsg.ForeColor = Color.Red; 

         } 

        } 

       } 
      } 
      catch (Exception ex) 
      { 
       Response.Write(ex.Message.ToString()); 
      } 

     } 



     public bool Connect(string SPURL, string SPUserName, string SPPassWord, string SPDomainName) 
     { 

      bool bConnected = false; 

      try 
      { 

       SPClientContext = new ClientContext(SPURL); 

       SPClientContext.Credentials = new NetworkCredential(SPUserName, SPPassWord, SPDomainName); 

       SPWeb = SPClientContext.Web; 

       SPClientContext.Load(SPWeb); 

       SPClientContext.ExecuteQuery(); 

       bConnected = true; 

      } 

      catch (Exception ex) 
      { 

       bConnected = false; 

       SPErrorMsg = ex.Message; 
       Response.Write(ex.Message.ToString()); 

      } 

      return bConnected; 

     } 



     public string UploadFile(Stream fs, string sFileName, string sSPSiteRelativeURL, string sLibraryName) 
     { 

      string sDocName = string.Empty; 

      try 
      { 

       if (SPWeb != null) 
       { 

        var sFileUrl = String.Format("{0}/{1}/{2}", sSPSiteRelativeURL, sLibraryName, sFileName); 



        Microsoft.SharePoint.Client.File.SaveBinaryDirect(SPClientContext, sFileUrl, fs, true); 



        sDocName = sFileName; 

       } 

      } 

      catch (Exception ex) 
      { 

       sDocName = string.Empty; 

       SPErrorMsg = ex.Message; 
       Response.Write(ex.Message.ToString()); 

      } 



      return sDocName; 

     } 
    } 
} 

は、それは誤りを通じて、それを正常に動作されています。

エラー:

は、問題を解決する方法を私を助けてください「最大要求の長さを超えて」。

答えて

0

あなたは、このようにSharePointでの最大要求の長さを定義することができます。全体管理で https://blogs.technet.microsoft.com/sammykailini/2013/11/06/how-to-increase-the-maximum-upload-size-in-sharepoint-2013/

を>アプリケーションの管理]> [Webアプリケーションの管理]> [所望のウェブアプリを選択し、ウェブではリボン

上の一般的な設定]をクリックします.config edit httpRuntimeこのようなノード(2GBのファイルと無制限の実行用):

+0

私はすでにこれを行っていますが、stiilには同じエラーがあります。 –

+0

どのような最大サイズを設定しましたか? – Nils

+0

私は500 MBを設定しました.20 MBのファイルをアップロードしているときにエラーが発生しました。 –

関連する問題