locked
LaunchFileAsync not working

    Question

  • I am using the below code to launch a file after writing on it. But it always fails to launch.Returned value is always false. Any idea what I might be doing wrong. Any help will be appreciated.

     var storageFolder = ApplicationData.Current.LocalFolder;

       var sampleFile = await storageFolder.CreateFileAsync("dataFile2.doc", CreationCollisionOption.ReplaceExisting);

        await FileIO.WriteTextAsync(sampleFile, "this is text 1")

    var launchFile = await storageFolder.GetFileAsync("dataFile2.doc");                                       

          var options = new Windows.System.LauncherOptions();
            options.DisplayApplicationPicker = true;
                                            

          bool success = await Windows.System.Launcher.LaunchFileAsync(launchFile, options);
             if (success)
                {
                        Debug.WriteLine("launch succeeded");
                   }
                else
                    {
                                                //Always returns false
                                         Debug.WriteLine("Launch failed");
                      }

                                                                              
    Wednesday, June 4, 2014 2:15 AM

Answers

  • Here's your issue:

    http://msdn.microsoft.com/en-us/library/windows/apps/Hh701471.aspx

    Launcher.LaunchFileAsync(IStorageFile) | launchFileAsync(IStorageFile) method

    Remarks

    The calling app must be visible to the user when the API is invoked.

    You can't do this at startup. 


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Friday, June 6, 2014 3:17 PM
    Moderator

All replies

  • Hi - I tried this exact code and it worked perfect. You do have Word installed, right?

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.


    Wednesday, June 4, 2014 2:10 PM
    Moderator
  • Thanks for your response.I have word installed. I am also not able to launch other kinds of file as well such as .txt. I am using Visual Studio 2013 express for windows and windows 8.1. Are you using the same?
    Thursday, June 5, 2014 6:18 AM
  • I am using Windows 8.1 Update 1 and VS2013 Ultimate with latest updates. Can you share the exact project that shows the problem?

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Thursday, June 5, 2014 2:33 PM
    Moderator
  • My ultimate goal is to create a .rdp file at runtime and launch it. Is it at all possible with this method or there is any alternative for this method.
    Thursday, June 5, 2014 9:36 PM
  • Just to give you some detail about project that I posted, from App.xamal.cs I am calling a asynchronous task defined in Class1.cs. The asynchronous task creates the .doc file and tries to launch it.
    Thursday, June 5, 2014 10:02 PM
  • Here's your issue:

    http://msdn.microsoft.com/en-us/library/windows/apps/Hh701471.aspx

    Launcher.LaunchFileAsync(IStorageFile) | launchFileAsync(IStorageFile) method

    Remarks

    The calling app must be visible to the user when the API is invoked.

    You can't do this at startup. 


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Friday, June 6, 2014 3:17 PM
    Moderator
  • Thanks for you reply that solved my first problem  I am able to Launch .doc file but I want to launch a .rdp file via Remote Desktop App. Does this Windows.System.Launcher.LaunchFileAsync puts a restriction on launching .rdp file? Is there any work around for that.
    Saturday, June 7, 2014 1:49 AM
  • See this:

    http://social.msdn.microsoft.com/Forums/windowsapps/en-US/3f8c1f3e-3d3a-4191-b747-1639c801ce1a/run-rdp-file?forum=winappswithcsharp


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Monday, June 9, 2014 3:58 PM
    Moderator