How do I allow a user to open a PDF stored in my UWP App?

Generation Continuum 191 Reputation points

I'm developing a UWP app and I want the user to be able to open a PDF stored in my app in Reader or a browser on the user's desktop.

I first used the following code-behind from an app bar button click:

            string filename1 = "ModelHouseAppStencils.pdf";

I got the following exception:

System.ComponentModel.Win32Exception: 'The system cannot find the file specified'

Then I used the code:

StorageFile file1 = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/ModelHouseAppStencils.pdf"));

I then got the following exception:

Exception thrown: 'System.IO.FileNotFoundException' in System.Private.CoreLib.dll

What do I do to solve this? Thanks.

Universal Windows Platform (UWP)
0 comments No comments
{count} votes

Accepted answer
  1. Generation Continuum 191 Reputation points

    The full path of my PDF file isn't exactly where you specified it should be. It's in this full path:


    How do I get rid of the top folder in this path or redirect my project to look for the PDF file in the current full path?


1 additional answer

Sort by: Most helpful
  1. Daniele 1,996 Reputation points

    At first check the properties of ModelHouseAppStencils.pdf: set "Copy to Output Directory" to "Copy if newer" or "Copy always" or set "Build Action" to "Content"


    StorageFile file = await Package.Current.InstalledLocation.GetFileAsync(System.IO.Path.Combine("Assets", "ModelHouseAppStencils.pdf"));
    await Windows.System.Launcher.LaunchFileAsync(file);