Search code examples
c#uwpsyncfusion

How to reference a file for StorageFile class in UWP?


In my UWP project I am trying to use Syncfusion's PDF library to fill out a PDF from. In order to open the template that I would like to use I constructed the following code:

//Browse and chose the file
Windows.Storage.StorageFolder storageFolder 
= Windows.Storage.ApplicationData.Current.LocalFolder;

StorageFile file 
= await storageFolder.GetFileAsync("/Assets/template.pdf");

//Creates an empty PDF loaded document instance
PdfLoadedDocument loadedDocument = new PdfLoadedDocument();

//Loads or opens an existing PDF document through Open method of PdfLoadedDocument class
await loadedDocument.OpenAsync(file);

The PDF, template.pdf, is located inside my Assets library in the project, and it's property "Copy to Output Directory" is set to "Copy always".

Running this code results in the following error: System.ArgumentException: 'Value does not fall within the expected range.'

What would be to correct syntax to use for this problem?


Solution

  • You can try:

    var file = await StorageFile.
         GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/template.pdf"));