0

I'm working on existing web application where users fill out some forms and upload files. When the application is submitted the files are synced with SharePoint site. The upload code is below.

// Upload files to the Document Set.
for (int i = 0; i < originalPathAndFileNames.Count; i++)
{
    string targetLocation = string.Format("{0}/{1}/{2}/{3}", web.ServerRelativeUrl, libraryName, documentSetName, newFileNames[i]);
    using (var fs = new System.IO.FileStream(originalPathAndFileNames[i], System.IO.FileMode.Open))
    {
        Microsoft.SharePoint.Client.File.SaveBinaryDirect(clientContext, targetLocation, fs, true);
    }
}

However, sometimes all files are uploaded to SharePoint, sometimes none, and sometimes only some of them. And this happens randomly. SharePoint is located on a different server than the web app, so I'm suspecting the problem could be with the transfer over HTTP.

Any ideas on how to solve this problem? Thanks.

sakura-bloom
  • 4,524
  • 7
  • 46
  • 61
  • Just to be clear, there is a ASP.NET web application that is acting as a Client to your SharePoint site? If this is the case, the first step would be (1) log all attempts at uploading files with any exceptions / return and (2) look at the SharePoint ULS logs at that same time. I'm fairly certain you don't get a correlation ID, but hopefully the server clocks are within a few seconds of each other /traffic isn't so frequent that multiple attempts occur within the same time frame. – Jaime Torres Oct 15 '13 at 15:07
  • You're right, it's an ASP.NET web app using Client Object Model. The web app does not throw any exceptions (and `SaveBinaryDirect` return type is `void`). But I will look into ULS logs. Thanks. – sakura-bloom Oct 15 '13 at 15:13
  • One way to check to see if your file uploaded correctly is to query your context and see if a valid file exists at your `targetLocation.` If what you're expecting to see there isn't there, it's probably a good time to log that something bad happened. – Jaime Torres Oct 15 '13 at 15:24

0 Answers0