我正在尝试编写一个可以自动执行的C#应用程序,以将2 GB .zip文件上载到Office365 SharePoint Online网站。但是,我似乎无法尝试任何方法。经过多次徒劳无功的尝试后,我一直在使用“Lists.asmx”服务参考,这看起来很有希望,但无论我如何配置,我都会不断获得例外。似乎应该有一个解决方案,如何使用C#将单个2 GB .zip文件上传到SharePoint Online?
对于凭据,我只是使用我用来手动登录SharePoint的凭据。
下面的代码抛出了最后一个catch块捕获的异常,并带有以下消息:
SOAP标头安全性未被理解
如果我使用ListsSoapClient(b, ea)
而不是no arg构造函数,则最后一个catch块会引发一个不同的异常:
内容类型(windows-1252)与绑定内容类型(utf-8)
不匹配
另外,作为附注:我假设ListsSoapClient()no-arg构造函数使用我在App.config文件中指定的绑定?
Program.cs的
string srcUrl = @"testingBACKUP.zip";
FileStream fStream = File.OpenRead(srcUrl);
string fileName = fStream.Name.Substring(3);
byte[] contents = new byte[fStream.Length];
fStream.Read(contents, 0, (int)fStream.Length);
fStream.Close();
EndpointAddress ea = new EndpointAddress("https://companyname.sharepoint.com/");
WSHttpBinding b = new WSHttpBinding();
b.Security.Mode = SecurityMode.TransportWithMessageCredential;
//b.Security.Message.ClientCredentialType = MessageCredentialType.Windows;
ListsSoapClient listService = new ListsSoapClient();//b, ea);
listService.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
listService.ClientCredentials.UserName.UserName = "<username>";
listService.ClientCredentials.UserName.Password = "<password>";
try
{
var testing = listService.GetListContentType("Company", "windows-1252");
string addAttach = listService.AddAttachment("Company", "1", fileName, contents);
}
catch (System.Web.Services.Protocols.SoapException ex)
{
// catch error
}
catch (Exception e)
{
}
的App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="ListsSoap"
closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="2000000" maxBufferPoolSize="2000000" maxReceivedMessageSize="2000000"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://companyname.sharepoint.com/_vti_bin/Lists.asmx"
binding="basicHttpBinding" bindingConfiguration="ListsSoap"
contract="SharePointListsReference.ListsSoap" name="ListsSoap" />
</client>
</system.serviceModel>
</configuration>
答案 0 :(得分:0)
我认为您无法将大文件上传到SharePoint Online。 SharePoint Online的限制最大为2GB文件。
这是链接...