UWP C# Opening a text file in Notepad.

VoyTec 671 Reputation points
2022-10-29T20:54:35.277+00:00

Is it possible that UWP app' can open a text file in Notepad (opening a Notepad)?

Developer technologies | Universal Windows Platform (UWP)
0 comments No comments
{count} votes

Accepted answer
  1. Junjie Zhu - MSFT 21,646 Reputation points
    2022-10-31T08:51:04.993+00:00

    Hello @VoyTec ,
    Welcome to Microsoft Q&A!

    You can refer to the document Launch the default app for a file to select the file opening method to select Notepad to open the txt file.

    async void DefaultLaunch()  
    {  
       // Path to the file in the app package to launch  
          string imageFile = @"images\test.png";  
            
       var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(imageFile);  
      
       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  
          }  
          else  
          {  
             // File launch failed  
          }  
       }  
       else  
       {  
          // Could not find file  
       }  
    }  
    

    Thank you.
    Junjie


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.