Search code examples
c#pythonwindows-10uwplaunching-application

windows UWP app LaunchAsync not launching .py files


This is my first question, so ill try my best to ask it in a better way.

I am using launchasync method in c# in my windows 10 UWP app. Behind a button click handler I am using it. Its working file with .txt files bcz it opens it with its default app, i.e. notepad, but when I try to open a python file with extension .py it doesn't even try to open it and does nothing.

Here is my code behind the button click event handler:

private async void button_Click(object sender, RoutedEventArgs e)
{
    var value = "";
    RTB.Document.GetText(Windows.UI.Text.TextGetOptions.AdjustCrlf, out value);
    var file = await ApplicationData.Current.LocalFolder.TryGetItemAsync("python2.py") as IStorageFile;

    if (file== null)
    {
        await ApplicationData.Current.LocalFolder.CreateFileAsync("python2.py");
        file = await ApplicationData.Current.LocalFolder.TryGetItemAsync("python2.py") as IStorageFile;
    }
    value+= "\ninput ('press enter to exit')";
    await FileIO.WriteTextAsync(file, value);
    var options = new LauncherOptions();
    options.DisplayApplicationPicker = true;
    await LaunchFileAsync(file);
}

Solution

  • Some of file types are blocked for security reason. '.exe', '.msi' and '.js' are documented on msdn. And as far as I know, '.cmd' and '.ps1' are also blocked. I don't know how to get the complete blacklist, but.. .py is also blocked, maybe.

    Launcher.LaunchFileAsync