none
System.Runtime.InteropServices.COMException when launching a file on Windows Phone RRS feed

  • Question

  • I am trying to open a pdf file using the below working code I previously used on another app,

    but this time I am getting System.Runtime.InteropServices.COMException when the flow hits this line: Windows.System.Launcher.LaunchFileAsync(pdffile);

    What is the meaning of this exception and how to get rid of it?

    Please note that without caring about this exception (disabling it), the file still cannot be opened

            public void openFile(string options)
            {
                System.Diagnostics.Debug.WriteLine("options: " + options);
                string optVal = JsonHelper.Deserialize<string[]>(options)[0];
                asyncOpen(optVal);
            }
    
            public async Task asyncOpen(string filename)
            {
                    filename = filename.Substring(2, filename.Length - 2);
                    filename = filename.Replace("//", "/").Replace("/", "\\");
                    Windows.Storage.StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
                    Debug.WriteLine("local: " + local.Path);
                    Windows.Storage.StorageFile pdffile = await local.GetFileAsync(filename);
                    Debug.WriteLine("pdffile: " + pdffile.Name);
                    //// Launch the pdf file.
                        Windows.System.Launcher.LaunchFileAsync(pdffile); 
            }


    s

    Monday, July 6, 2015 12:33 PM

Answers

All replies

  • Hi SeDevWP,

    Welcome to the Developing Universal Windows apps forum! 
    Please read the sticky posts, especially the Guide to posting: subject line tags and Known Issues for Windows 10 SDK and Tools

    First please make sure that "pdffile" exists in your app, then by default the .pdf document is not supported on the Windows Phone, if you want to open a pdf file in your application by using the Windows.System.Launcher.LaunchFileAsync(pdffile), please make sure that you have installed an app on your phone which can open the pdf file. For example:the Adobe Reader/the PDF Reader.

    If you do not installed an app that can open the pdf file on your phone, then maybe you need to check some third-party library to meet your requirement.

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Tuesday, July 7, 2015 3:27 AM
    Owner
  • Thanks for your reply, Amy.

    I am using wp8.1.

    Yes, the file exists and I saw it also using wpowertools (otherwise maybe I would have filenotfoundException or like).

    Yes, I do have adobe reader installed.

    Tuesday, July 7, 2015 7:24 AM
  • Hi Amy, Please do you have any news?
    Thursday, July 9, 2015 10:52 AM
  • it works calling it from UI thread. I wonder why there is such COMException...
    Thursday, July 9, 2015 1:19 PM
  • Hi eeadev,

    I am very sorry about the late reply.

    Based on your description, I know that it works well when calling from the UI thread, then where do you call it and meet such COMException...?

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, July 20, 2015 8:32 AM
    Owner
  • it is fixed here: http://stackoverflow.com/a/31315711/1948785

    thanks

    Monday, July 20, 2015 8:34 AM
  • Hi eeadev,

    Glad to know. :)

    Thank you very much for sharing the solution to us.

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, July 20, 2015 8:44 AM
    Owner