简体   繁体   English

在尝试Process.Start()之前,如何以编程方式检查文件关联存在的文件?

[英]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.

相关问题 在process.start();之前检查该进程是否存在。 - Check if the process exists before process.start(); 如何确保如果文件存在,它会启动Process.Start? - How to make sure that if a file exists, it starts a Process.Start? File.Exists 返回false,Process.Start() 无法启动文件,但它确实存在 - File.Exists returns false,Process.Start() can't start the file,But it actually exists 即使文件存在,Process.start也会导致找不到文件 - Process.start results in file not found even though the file exists 如何确定应用程序存在? (Process.Start可以找到它们) - How to determine is app exists? (Process.Start can find them) 在VB.NET中检查使用process.start()启动的文件中的更改 - In VB.NET check for changes in a file launched with process.start() 如何在继续之前强制Process.Start()完成? - How do I force Process.Start() to complete before proceeding? 在执行Process.Start之前,如何刷新表单对象属性的缓冲区? - How can I flush buffer of form object properties BEFORE a Process.Start is executed? 如果文件类型没有关联程序,如何使用 Process.Start 打开文件? - How to open file with Process.Start if there is no associated program for the file type? Process.Start找不到指定的文件,但是绝对存在-为什么? - Process.Start can not find file specified, but it is definitely there - why?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM