【问题标题】:Why Process.Start method always shows the "Open With" dialog为什么 Process.Start 方法总是显示“打开方式”对话框
【发布时间】: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


【解决方案1】:

我不知道为什么/如何,但是在卸载我昨天安装的 TechSmith Snagit 后我的问题解决了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-10
    • 1970-01-01
    • 1970-01-01
    • 2012-03-05
    • 1970-01-01
    • 2019-01-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多