gpt4 book ai didi

Sharepoint 2013 客户端对象模型文件大于 2 Mb 异常

转载 作者:行者123 更新时间:2023-12-04 00:52:11 24 4
gpt4 key购买 nike

我是 Sharepoint 和客户端对象模型的新手。我遇到了一个问题,无法解决这个问题。我想在 Sharepoint 2013 中使用客户端对象模型上传超过 10 MB 的文件。我得到以下异常

The request message is too large. The server does not allow messages that are larger than 2097152 bytes.

我什么都试过了。这是我做过的事情的 list

1- 更改了我本地 Web 应用程序的 web.config 文件中的设置

<system.web>
<httpRuntime useFullyQualifiedRedirectUrl="true" maxRequestLength="2147483647" requestLengthDiskThreshold="2147483647" executionTimeout="18000"/> </system.web>

<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147483647" />
</requestFiltering>
</security>
</system.webServer>

2- 在我服务器的 powershell 中运行以下命令并重新启动 IIS 中的应用程序。甚至重新启动了整个 IIS。

$ws = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$ws.ClientRequestServiceSettings.MaxReceivedMessageSize = 2147483647
$ws.Update()

这是我的代码:

private void UploadDataToSharepointTest(List<UploadData> pDataObjList)
{
string lServerUrl = @"http://xxxxxxx:2000/";
string lFolderName = DateTime.Now.ToString(@"yyyyMMddHHmmss");


ClientContext context = new ClientContext(lServerUrl);
context.AuthenticationMode = ClientAuthenticationMode.Default;
context.Credentials = new System.Net.NetworkCredential("user", "password", "domain");

Web web = context.Web;
List docs = web.Lists.GetByTitle("ABC");
Folder lNewFolder = web.Folders.Add(lServerUrl + "ABC/" + lFolderName + "/");
docs.Update();

int fileIndex = 1;
foreach (var item in pDataObjList)
{
FileCreationInformation newFile = new FileCreationInformation();
newFile.Content = System.IO.File.ReadAllBytes(item.CompleteFilePath);
newFile.Url = fileIndex.ToString() + "-" + item.fileName;
fileIndex++;

Microsoft.SharePoint.Client.File uploadFile = lNewFolder.Files.Add(newFile);

context.Load(uploadFile);
context.ExecuteQuery();

Dictionary<string, string> metadata = new Dictionary<string, string>();
metadata.Add("Comments", item.comments);
metadata.Add("Plan_x0020_Size", item.planSize);
metadata.Add("Density", item.density);
metadata.Add("First_x0020_Name", txtFirstName.Text.Trim());
metadata.Add("Last_x0020_Name", txtLastName.Text.Trim());
metadata.Add("Company", txtCompany.Text.Trim());
metadata.Add("Contact", txtContact.Text.Trim());
metadata.Add("Additional_x0020_Comments", txtAdditionalComments.Text.Trim());

Microsoft.SharePoint.Client.ListItem items = uploadFile.ListItemAllFields;
context.Load(items);
context.ExecuteQuery();

foreach (KeyValuePair<string, string> metadataitem in metadata)
{
items[metadataitem.Key.ToString()] = metadataitem.Value.ToString();
}

items.Update();
context.ExecuteQuery();
}

}

注意:我可以上传小文件。

最佳答案

如果使用内置上传功能,文件大小有限制。

要上传大文件,请使用文件流上传。

看看下面的文章:

http://blogs.msdn.com/b/sridhara/archive/2010/03/12/uploading-files-using-client-object-model-in-sharepoint-2010.aspx

关于Sharepoint 2013 客户端对象模型文件大于 2 Mb 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20076871/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com