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
Next
uploadFile.ListItemAllFields.Update()
context.ExecuteQuery()
Next
End Using
End Sub