【问题标题】:How to bring up the "Windows cannot open this file" dialog?如何弹出“Windows 无法打开此文件”对话框?
【发布时间】:2010-10-27 09:47:49
【问题描述】:

我的用户可以将文档附加到应用程序中的各种实体。当然,如果用户 A 附加了一个 .TIFF 文件,用户 B 可能没有该类型文件的查看器。

所以我希望能够调出这个对话框:

alt text http://www.angryhacker.com/toys/cannotopen.png

我的应用程序是带有 VS2005 的 C#。
目前我做 Process.Start 并传入文件名。如果没有找到关联,则抛出异常。

【问题讨论】:

    标签: c# visual-studio-2005 file-association process.start


    【解决方案1】:
    Process pr = new Process();
    pr.StartInfo.FileName = fileTempPath;
    pr.StartInfo.ErrorDialog = true; // important
    pr.Start();
    

    【讨论】:

    • 这个更好,独立于平台。
    【解决方案2】:

    应该这样做:

    System.Diagnostics.Process p = new System.Diagnostics.Process();
    p.StartInfo.FileName = "rundll32.exe";
    p.StartInfo.Arguments = "shell32.dll,OpenAs_RunDLL " + yourFileFullnameHere;
    
    p.Start();
    

    【讨论】:

    • 这种方法的问题是每次都会弹出对话框。我想如果我得到一个 Win32Exception 说明没有关联,我应该只执行这段代码。
    • 请注意,OpenAs_RunDLL 是无证的,does not always work.
    猜你喜欢
    • 2021-10-26
    • 2016-11-14
    • 1970-01-01
    • 1970-01-01
    • 2016-03-14
    • 2014-04-06
    • 2013-03-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多