我试图编写一个可以自动执行的C#应用程序,以便将2GB的.zip文件上传到Office365 SharePoint在线站点。然而,我似乎无法得到任何方法,我试图工作。经过多次徒劳无功的尝试,我一直在尝试使用"Lists.asmx“服务引用,这似乎很有希望,但无论我如何配置,我都会遇到异常。似乎应该有一个解决方案,如何使用C#?将单个2GB的.zip文件上传到SharePoint Online。
对于凭据,我只是使用了用于手动登录到SharePoint online的凭据。
下面的代码抛出由最后一个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>
发布于 2015-08-19 06:50:48
我认为你不能上传大文件到SharePoint在线。SharePoint Online的限制是最大文件2GB。
这是链接..。
https://stackoverflow.com/questions/32083114
复制相似问题