Question

leidge1 on Tue, 09 May 2017 12:04:40


Hi,

We have an outlook plugin that save mails to a Sharepoint 2010 document library using CSOM and SaveBinaryDirect.
Soon we will be updating MS Office from 2010/2013 to Office 265 (Office 2016).

I've installed Office 2016 on my own machine and tried to save a mail with the plugin.
This fails with the following errormessage:


Searched the web and found an alternative way of uploading the files using FileCreationInformation.
This works, but requires changing a few settings on the sharepoint server to be able to upload files larger than 3 MB.
However.  My main issue is that the new upload method is 3-4 times slower than using SaveBinaryDirect.

Could someone tell me why using SaveBinaryDirect doesn't work after installing Office 2016?
And if there is any workaround to the problem.

I created a Windows Forms Application to test the two upload methods.

private void buttonSaveBinaryDirect_Click(object sender, EventArgs e)
{
    Stopwatch sw = Stopwatch.StartNew();
    string UploadUser = "spmailupload";
    string UploadUserPassword = "mypassword";
    string UploadUserDomain = "mydomain.local";
    
    ClientContext context = new ClientContext("http://intraweb.mydomain.local");
    NetworkCredential cred = new NetworkCredential(UploadUser, UploadUserPassword, UploadUserDomain);
    context.Credentials = cred;

    using (FileStream fs = new FileStream(@"C:\Temp\TestMessage.msg", FileMode.Open))
    {
        try
        {
            Microsoft.SharePoint.Client.File.SaveBinaryDirect(context, "/Mail/TestMessage.msg", fs, true);
            sw.Stop();
            System.Windows.Forms.MessageBox.Show("File uploaded successfully in " + sw.Elapsed.TotalSeconds.ToString() + " seconds", "Success", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
        }
        catch (System.Net.WebException ex)
        {
            string ErrorMessage = "Could not upload file to Sharepoint!" + Environment.NewLine + "See error message below: " + Environment.NewLine + Environment.NewLine + ex.ToString();
            System.Windows.Forms.Clipboard.SetText(ex.ToString());
            System.Windows.Forms.MessageBox.Show(ErrorMessage, "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
        }
    }
 }

private void buttonFileCreationInformation_Click(object sender, EventArgs e)
{
    Stopwatch sw = Stopwatch.StartNew();
    string UploadUser = "spmailupload";
    string UploadUserPassword = "mypassword";
    string UploadUserDomain = "mydomain.local";
    
    ClientContext context = new ClientContext("http://intraweb.mydomain.local");
    NetworkCredential cred = new NetworkCredential(UploadUser, UploadUserPassword, UploadUserDomain);
    context.Credentials = cred;

    var fileCreationInformation = new FileCreationInformation();
    fileCreationInformation.Content = System.IO.File.ReadAllBytes(@"C:\Temp\TestMessage.msg");
    fileCreationInformation.Overwrite = true;
    fileCreationInformation.Url = "/Mail/TestMessage.msg";
    List CurrentList = context.Web.Lists.GetByTitle("Mail");
    CurrentList.RootFolder.Files.Add(fileCreationInformation);
    
    try
    {
        context.ExecuteQuery();
        sw.Stop();
        System.Windows.Forms.MessageBox.Show("File uploaded successfully in " + sw.Elapsed.TotalSeconds.ToString() + " seconds", "Success", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
    }
    catch (System.Exception ex)
    {
        string ErrorMessage = "Could not upload file to Sharepoint!" + Environment.NewLine + "See error message below: " + Environment.NewLine + Environment.NewLine + ex.ToString();
        System.Windows.Forms.Clipboard.SetText(ex.ToString());
        System.Windows.Forms.MessageBox.Show(ErrorMessage, "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
    }
}


Both methods work on a computer with Office 2010 or 2013 installed.
Only the FileCreationInformation version works on a computer with Office 2016 installed.


Replies

Dennis Guo on Thu, 11 May 2017 08:32:50


Hi,

I suggest you use other two ways to upload the large files using CSOM.

1. ContentStreamproperty on the  FileCreationInformation  class

2. StartUpload, ContinueUploadand FinishUploadmethods on the  File  class

More information is here:

Large file upload with CSOM

https://dev.office.com/patterns-and-practices-detail/1876

Best Regards,

Dennis

leidge1 on Fri, 12 May 2017 11:38:27


Hi Dennis,

Thanks for taking the the reply.

Unfortunately Sharepoint 2010 does not support the ContentStream property.
So I can't use any of these options.

leidge

Dennis Guo on Mon, 15 May 2017 01:42:16


Hi,

Please try to set RequestTimeout property of ClientContext when using the SaveBinaryDirect method.

https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.clientcontext_members(v=office.14).aspx

More information:

SharePoint 2010: Uploading Large Files to SharePoint

https://social.technet.microsoft.com/wiki/contents/articles/20299.sharepoint-2010-uploading-large-files-to-sharepoint.aspx

Issues Uploading Large Files To SharePoint

https://blogs.technet.microsoft.com/praveenh/2012/11/15/issues-uploading-large-files-to-sharepoint/

Best Regards,

Dennis


Please remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com


leidge1 on Tue, 16 May 2017 13:02:36


Thanks for the input.  Those were useful links.

Finally found the problem though.
The problem was not Office 2016.  
It was Kaspersky antivirus that I had installed around the same time for evaluation.
Uninstalled Kaspersky and installed Bitdefender instead and everything is working as normal.  
Even without modifying the code.

Sorry for wasting your time Dennis.

leidge


Dennis Guo on Wed, 17 May 2017 01:22:35


Hi leidge,

Glad to hear that you solve this issue, thanks for your sharing!

Best Regards,

Dennis