I am creating a method to UploadDocument_FromStream() method which has one parameter -- Stream file.
I am having trouble trying to keep my SharePoint connection open to allow me to upload my Stream file to SharePoint. I think the issue is due to the fact that I am executing a query then trying to upload to SharePoint.
Is this the best way to handle Uploading to SharePoint with a MemoryStream?
UploadDocument_FromStream()
public void UploadDocument_FromStream(Stream file)
{
using (var clientContext = OpenConnectionToSharePoint())
{
if (file == null) throw new Exception("Stream cannot be null");
using (clientContext)
{
var list = clientContext.Web.Lists.GetByTitle("Documents");
clientContext.Load(list.RootFolder);
clientContext.ExecuteQuery();
Microsoft.SharePoint.Client.File.SaveBinaryDirect(clientContext, "/shared documents/test.pdf", file, true);
}
}
Also should note - that I am using SharePoint.Client.dll or COM approach.