pnpframework
pnpframework copied to clipboard
Uploading file to onprem Sharepoint hangs in WPF .net 6 application
'ello
The following code just hangs on the ExecuteQuery() - it does not thows an error, it just never returns. The exact same code works fine in a WinForms .net 6 application
` public partial class App : Application { protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e);
var filePath = @"C:\temp\raw Material Receipts\RMR_20220224062549.pdf";
var fs = new FileStream(filePath, FileMode.Open);
var x1 = new AuthenticationManager();
var ctx = x1.GetOnPremisesContext("https://docs.namibmills.com.na/");
var lib = ctx.Web.Lists.GetByTitle("Raw Material Receipts");
var newFileInfo = new FileCreationInformation
{
ContentStream = fs,
Url = $"{Path.GetFileName(filePath)}",
Overwrite = true
};
var file = lib.RootFolder.Files.Add(newFileInfo);
ctx.Load(file);
ctx.ExecuteQuery();
}
}`
@HeinA : Please try with async methods ExecuteQueryAsync()
. Also, since you're using plain CSOM you can consider using PnP Core SDK: here's the information on file uploading (https://pnp.github.io/pnpcore/using-the-sdk/files-intro.html#adding-files-uploading and https://pnp.github.io/pnpcore/using-the-sdk/files-large.html#uploading-large-files). Here's a WPF sample application: https://pnp.github.io/pnpcore/demos/Demo.WPF/README.html
@HeinA : Please try with async methods
ExecuteQueryAsync()
. Also, since you're using plain CSOM you can consider using PnP Core SDK: here's the information on file uploading (https://pnp.github.io/pnpcore/using-the-sdk/files-intro.html#adding-files-uploading and https://pnp.github.io/pnpcore/using-the-sdk/files-large.html#uploading-large-files). Here's a WPF sample application: https://pnp.github.io/pnpcore/demos/Demo.WPF/README.html
Thank you very much