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 on Windows Phone 8 Emulator
, When i click on the item in the longlist selector i get the below 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 this ? what am i doing wrong here?
EDIT
I have set this as well , change it's build action.
Right click on PDF document.
Click on properties.
Change Build Action from None to Content