WPF打开菜单

时间:2015-03-12 20:56:11

标签: c# wpf windows

在WPF应用程序中是否有办法打开“打开方式”对话框,在Windows资源管理器中右键单击文件并选择“打开方式”时会看到该对话框?

3 个答案:

答案 0 :(得分:3)

以下是我最终处理此问题的方法。我在此处添加了一些异常处理,它按预期工作。

Process.Start("rundll32.exe", string.Format("shell32.dll,OpenAs_RunDLL {0}", somefile.ext));

答案 1 :(得分:-1)

我认为你在谈论OpenFileDialog

    // Create OpenFileDialog 
     Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
     // Set filter for file extension and default file extension 
     dlg.DefaultExt = ".png";
     dlg.Filter = "All Image Files (*.png;*.bmp;*.jpg;*jpeg)|*.png;*.bmp;*.jpg;*jpeg|JPEG Files (*.jpeg)|*.jpeg|PNG Files (*.png)|*.png|JPG Files (*.jpg)|*.jpg|BMP Files (*.bmp)|*.bmp";
     // Display OpenFileDialog by calling ShowDialog method 
      Nullable<bool> result = dlg.ShowDialog();

    // Get the selected file name and display in a TextBox 
   if (result == true)
   {

   }

如果您正在谈论文件关联,那么您可以使用 http://www.jrsoftware.org/isinfo.php。安装后,文件将与您的扩展相关联,执行文件路径可以通过命令行参数访问。

答案 2 :(得分:-1)

此示例演示如何使用关联程序打开文件。它显示了如何在记事本中打开文本文档,如何在默认查看器中打开图像或如何在默认Web浏览器中打开URL地址。

使用Process.Start方法启动应用程序。文件路径或URL作为参数传递。

// open text file in notepad (or another default text editor)
System.Diagnostics.Process.Start(@"c:\textfile.txt");

// open image in default viewer
System.Diagnostics.Process.Start(@"c:\image.jpg");

// open url in default web browser
System.Diagnostics.Process.Start("http://www.csharp-examples.net");

// open PDF file
System.Diagnostics.Process.Start(@"c:\document.pdf");

同样,您可以从.NET应用程序中打开Word文档或任何其他文件。