Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在Windows 8 Metro应用程序C中打开文件#_C#_Microsoft Metro - Fatal编程技术网

C# 在Windows 8 Metro应用程序C中打开文件#

C# 在Windows 8 Metro应用程序C中打开文件#,c#,microsoft-metro,C#,Microsoft Metro,我有一个带有文件路径的数组(如“C:\…”),我想用默认应用程序从我的应用程序中打开它们。假设它是一个列表,当我单击其中一个时,它就会打开 这是异步启动文件的方法: await Windows.System.Launcher.LaunchFileAsync(fileToLaunch); 它需要Windows.Storage.StorageFile类型的文件,该文件具有Path只读属性,因此我无法设置路径。点击/点击后,我如何打开它们?从我在评论中的链接复制: // Path to the fi

我有一个带有文件路径的数组(如“C:\…”),我想用默认应用程序从我的应用程序中打开它们。假设它是一个列表,当我单击其中一个时,它就会打开

这是异步启动文件的方法:

await Windows.System.Launcher.LaunchFileAsync(fileToLaunch);

它需要
Windows.Storage.StorageFile
类型的文件,该文件具有
Path
只读属性,因此我无法设置路径。点击/点击后,我如何打开它们?

从我在评论中的链接复制:

// Path to the file in the app package to launch
   string exeFile = @"C:\Program Files (x86)\Steam\steamapps\common\Skyrim\TESV.exe";

   var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(exeFile);

   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
      }
   }
当然,您可以省略
var options=**
-部分,这样应用程序选择器就不会被打开

或者,您可以使用:

StorageFile fileToLaunch = StorageFile.GetFileFromPathAsync(myFilePath);
await Windows.System.Launcher.LaunchFileAsync(fileToLaunch);

从评论中的“我的链接”复制:

// Path to the file in the app package to launch
   string exeFile = @"C:\Program Files (x86)\Steam\steamapps\common\Skyrim\TESV.exe";

   var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(exeFile);

   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
      }
   }
当然,您可以省略
var options=**
-部分,这样应用程序选择器就不会被打开

或者,您可以使用:

StorageFile fileToLaunch = StorageFile.GetFileFromPathAsync(myFilePath);
await Windows.System.Launcher.LaunchFileAsync(fileToLaunch);

你应该使用这个方法
在类型
StorageFile



此方法用于获取文件,如果您已经有
路径

,则应使用此方法
在类型
StorageFile



如果您已经有
路径

则使用此方法获取文件答案在此示例中:

简言之,答案是:

// First, get the image file from the package's image directory.
string fileToLaunch = @"images\Icon.Targetsize-256.png";
var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(fileToLaunch);

// Next, launch the file.
bool success = await Windows.System.Launcher.LaunchFileAsync(file);

答案在此示例中:

简言之,答案是:

// First, get the image file from the package's image directory.
string fileToLaunch = @"images\Icon.Targetsize-256.png";
var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(fileToLaunch);

// Next, launch the file.
bool success = await Windows.System.Launcher.LaunchFileAsync(file);
最佳解决方案是:

stringfilepath=@”file:///C:\某处\某物.pdf“;
if(filePath!=null)
{
bool success=wait Windows.System.Launcher.launchurisync(新Uri(文件路径));
如果(成功)
{
//文件启动
}
其他的
{
//文件启动失败
}
}
Tha应用程序使用系统默认应用程序启动,在本例中使用Adobe Reader。

最佳解决方案是:

stringfilepath=@”file:///C:\某处\某物.pdf“;
if(filePath!=null)
{
bool success=wait Windows.System.Launcher.launchurisync(新Uri(文件路径));
如果(成功)
{
//文件启动
}
其他的
{
//文件启动失败
}
}
Tha应用程序使用系统默认应用程序启动,本例中使用Adobe Reader。

检查此项:检查此项: