【发布时间】:2020-09-25 07:21:03
【问题描述】:
我正在开发一个 WPF 应用程序,该应用程序使用 Process.Start() 方法通过默认查看器应用程序打开图像和 PDF 文件。
有什么问题?
每次我调用Process.Start() 方法时,都会显示“打开方式”对话框,即使我选中了“始终使用此应用打开 .jpg 文件”选项。
这是我的 C# 代码:
public void Open(string fileName, bool isPdf)
{
var sharedFolderPath = AppCore.Settings.SharedFolder.Path;
string message;
if (sharedFolderPath is null)
{
message = Resources.EmptySharedFolderErrorMessage;
AppCore.ShowDialog(AppCore.GetMessageDialog(message));
return;
}
var path = Path.Combine(sharedFolderPath, fileName);
if (File.Exists(path))
{
try
{
if (isPdf || AppCore.Settings.ImageViewerSettings.OpenInWindowsDefaultApp)
{
Process.Start(path);
}
else
{
var imageViewerWindow = new ImageViewerWindow(path);
imageViewerWindow.ShowDialog();
}
}
catch (Exception ex)
{
AppCore.Logger.Info("Opening shared file failed.");
AppCore.Logger.Exception(ex);
}
return;
}
message = string.Format(Resources.SharedFolderFileNotFoundMessage, fileName);
AppCore.ShowDialog(AppCore.GetMessageDialog(message));
}
我的更多细节问题: https://imgur.com/a/JQyIMZE
已编辑
我创建了一个简单的 WPF 项目并尝试使用Process.Start() 方法打开图像。在新项目中,图像是使用默认应用打开的,但没有显示“打开方式”对话框。
【问题讨论】:
-
尝试检测打开文件类型(stackoverflow.com/a/162351/4329813)的当前默认应用程序是什么?然后将默认应用程序路径传递给 Process.FileName
-
看起来没有为您尝试打开的文件系统类型注册默认应用程序。
-
这不是 API 的问题。这是 Process.Start 的默认行为。用户需要修复的东西。
-
@BionicCode 我该如何解决这个问题?
-
在 Windows 默认应用设置中为照片查看器注册的 Windows 10 照片应用。
标签: c# wpf process.start