0

I'm trying to write a C# application that can be executed automatically to upload a 2 GB .zip file to a Office365 SharePoint Online site. However, I can't seem to get any approach I try to work. After many fruitless attempts, I've been diving into using the "Lists.asmx" service reference, which appears promising, but I keep getting exceptions no matter how I configure things. It seems like there should be a solution out there for this, how can I upload a single 2 GB .zip file to SharePoint Online using C#?

For credentials, I've simply been using the credentials I'd use to manually log in to SharePoint online.

The code below throws an exception caught by the last catch block with the message:

SOAP header Security was not understood

If I use ListsSoapClient(b, ea) rather than the no arg constructor, a different exception is thrown caught by the last catch block stating:

the content type (windows-1252) does not match the binding content type (utf-8)

Also, as a side note: I'm assuming the ListsSoapClient() no-arg constructor uses the binding I've specified in the App.config file?

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>
TylerH
  • 20,799
  • 66
  • 75
  • 101
Joe L
  • 25
  • 1
  • 5

1 Answers1

0

I think you can't upload large file to SharePoint Online. The limitation for SharePoint Online is maximum a file 2GB.

Here is the link...

https://support.office.com/en-sg/article/SharePoint-Online-and-OneDrive-for-Business-software-boundaries-and-limits-8f34ff47-b749-408b-abc0-b605e1f6d498?ui=en-US&rs=en-SG&ad=SG

Nic
  • 1,014
  • 7
  • 15
  • Ok, thanks for that reference. Let me rephrase the question to "how can I upload 2GB files using C#?" – Joe L Aug 19 '15 at 23:28
  • Joe I didn't try to upload such large file before but i got 2 reference you can refer... Login - http://stackoverflow.com/questions/6382583/use-credentials-to-interact-with-the-client-object-model-of-sharepoint Upload to SharePoint - http://sharepoint.stackexchange.com/questions/119392/attach-file-in-customlist-item-using-sharepoint-client-object – Nic Aug 20 '15 at 01:14
  • The current filesize limit mentioned in your link is 15GB. CC @JoeL (it's been 4 years, but just FYI). – TylerH Apr 09 '19 at 21:08