[英]How can I programmatically check file that a file association exists before attempting to Process.Start() it?
My .Net Windows Forms application generates a PDF report, which I want to show to the user. 我的.Net Windows窗体应用程序生成PDF报告,我想向用户显示该报告。
Instead of just assuming the client PC has a PDF viewer installed and blindly throwing the PDF at the Operating System to open, is there a way to check against the list of file associations on the client beforehand, then show a " you need a PDF viewer application installed - here's a couple of suggestions.. " dialog if PDF isn't a registered type? 而不是假设客户端PC安装了PDF查看器并盲目地将PDF放在操作系统中打开, 有没有办法事先检查客户端上的文件关联列表 ,然后显示“ 你需要一个PDF查看器安装的应用程序 - 这里有几个建议.. “对话框,如果PDF不是注册类型?
I've found a lot of questions and answers about changing or registering file associations, but I just want an easy way to query the list, not change it. 我发现了很多关于更改或注册文件关联的问题和答案,但我只是想要一种简单的方法来查询列表,而不是更改它。
I'd like a solution that works on Windows XP onwards (WinXP, Vista, Win7). 我想要一个适用于Windows XP以上的解决方案(WinXP,Vista,Win7)。
Thanks for your help 谢谢你的帮助
It's better not use the registry directly but rely on the Windows API instead. 最好不要直接使用注册表,而是依赖Windows API。 Here is a link on SO that gives a .NET solution: How do I get File Type Information based on extension?
这是一个提供.NET解决方案的SO链接: 如何根据扩展名获取文件类型信息? (not MIME) in c#
c#中的(不是MIME)
I found there is a .pdf key in the registry, maybe it can help you: 我发现注册表中有一个.pdf密钥,也许它可以帮助你:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\.pdf]
"Content Type"="application/pdf"
@="AcroExch.Document"
[HKEY_CLASSES_ROOT\.pdf\OpenWithList]
@=""
[HKEY_CLASSES_ROOT\.pdf\OpenWithList\AcroRd32.exe]
@=""
[HKEY_CLASSES_ROOT\.pdf\ShellEx]
[HKEY_CLASSES_ROOT\.pdf\ShellEx\{8895b1c6-b41f-4c1c-a562-0d564250836f}]
@="{DC6EFB56-9CFA-464D-8880-44885D7DC193}"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.