SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Trying to eliminate a performance bottleneck on a method doing file and metadata uploads. According to the profiler on a line-by-line of the decompiled code, the majority of time is spent on context.ExecuteQuery(). Below is the code. Any and all suggestions and insights greatly appreciated.

Public Shared Sub UploadDocuments(ByVal siteURL As String, _
                                 ByVal credentials As Net.NetworkCredential, _
                                 ByVal documentListName As String, _
                                 ByVal documentListURL As String, _
                                 ByVal sharePointUploads As List(Of SharePointDocumentToSave))

    Using context As New ClientContext(siteURL)
        If Not credentials Is Nothing Then
            context.Credentials = credentials
        End If

        AddHandler context.ExecutingWebRequest, AddressOf ClientContextExecutingWebRequest

        Dim documentsList As List = context.Web.Lists.GetByTitle(documentListName)

        For Each documentUpload As SharePointDocumentToSave In sharePointUploads
            Dim fci = New FileCreationInformation()
            With fci
                .Url = siteURL & documentListURL & documentUpload.DocumentName
                .Content = documentUpload.DocumentFile
                .Overwrite = True
            End With

            Dim uploadFile As Microsoft.SharePoint.Client.File = documentsList.RootFolder.Files.Add(fci)

            For Each pair As KeyValuePair(Of String, String) In documentUpload.MetaData
                uploadFile.ListItemAllFields(pair.Key) = pair.Value


    End Using

End Sub
share|improve this question

This is totally normal when working with Client Object Model (CSOM). All operations are batched and not performed until you fire them away using ExecuteQuery() or ExecuteQueryAsync(). The rest of your code is just setting of local properties, which is converted into an XML format, which is sent to SharePoint at the time you execute the ExecuteQuery method.

share|improve this answer
Thanks for the reply. In particular, would you have any idea why it might take 20 seconds for a 20KB file to upload? This is being executed over a gigabit network. – Alfred Apr 5 '12 at 13:23

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.