Starts the default app associated with the specified file or URI.

Launch a file contained in the app package

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)
   {
      // Launch the retrieved file
      var success = await Windows.System.Launcher.LaunchFileAsync(file);

      if (success)
      {
         // File launched
      }
      else
      {
         // File launch failed
      }
   }
   else
   {
      // Could not find file
   }
}

 

Launch a URI

// The URI to launch
string uriToLaunch = @"http://www.bing.com";

// Create a Uri object from a URI string 
var uri = new Uri(uriToLaunch);

// Launch the URI
async void DefaultLaunch()
{
   // Launch the URI
   var success = await Windows.System.Launcher.LaunchUriAsync(uri);

   if (success)
   {
      // URI launched
   }
   else
   {
      // URI launch failed
   }
}

相关文章:

  • 2021-06-20
  • 2022-12-23
  • 2022-02-23
  • 2021-06-30
  • 2022-01-31
  • 2021-11-15
  • 2021-07-06
猜你喜欢
  • 2022-01-30
  • 2022-03-04
  • 2021-06-25
  • 2021-04-14
  • 2021-11-11
  • 2021-10-25
  • 2022-12-23
相关资源
相似解决方案