pnpframework icon indicating copy to clipboard operation
pnpframework copied to clipboard

Uploading file to onprem Sharepoint hangs in WPF .net 6 application

Open HeinA opened this issue 2 years ago • 2 comments

'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 avatar Feb 28 '22 12:02 HeinA

@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

jansenbe avatar Mar 17 '22 08:03 jansenbe

@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

HeinA avatar Apr 17 '22 13:04 HeinA