Open PDF file in emulator

I have this code:

private async void LaunchPDF(string name) { var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(name); if (file != null) { // Set the option to show the picker var options = new Windows.System.LauncherOptions(); options.DisplayApplicationPicker = true; // Launch the retrieved file bool success = await Windows.System.Launcher.LaunchFileAsync(file, options); if (success) { // File launched Debug.WriteLine("File Launched"); } else { // File launch failed Debug.WriteLine("File Launched Failed"); } } else { // Could not find file Debug.WriteLine("File not found"); } } 

This method is called here:

 private void longListSelector_SelectionChanged(object sender, SelectionChangedEventArgs e) { MyObject item = longListSelector.SelectedItem as MyObject; LaunchPDF("Data/PDF/" + item.SubTitle + ".pdf"); } 

I am testing Windows Phone 8 Emulator I click on an item in the longlist selector, I get the following error:

 {System.ArgumentException: Value does not fall within the expected range. at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at MyApp.Classes.Views.PDFPage.<LaunchPDF>d__0.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>b__0(Object state)} 

How to fix it? what am i doing wrong here?

EDIT

I also installed this, changed its build action.

Right-click the PDF document.

Click on properties.

Change assembly action from none to content

0
source share

All Articles