C#打开文件,默认应用程序及参数 [英] c# open file with default application and parameters

查看:197
本文介绍了C#打开文件,默认应用程序及参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最简单的方法来打开与默认应用程序文件是:

The most easy way to open a file with the default application is:

System.Diagnostics.Process.Start(@"c:\myPDF.pdf");

不过,我想知道是否存在一种方法,参数设置为默认应用程序,因为我想在一个确定的页码,打开PDF文件。

However, I would like to know if exists a way to set parameters to the default application, because I would like to open a pdf in a determinate page number.

我知道我能做到这一点创建一个新的进程并设置参数,但通过这种方式,我需要指出应用程序的路径,我想有一个便携式的应用程序,而不是有设置路径应用程序的每一次我使用其他计算机中的应用。我的想法是,我想到的是,计算机已经安装了PDF阅读器,只说些什么页面打开。

I know how can I do it creating a new process and set the parameters, but in this way I need to indicate the path of the application, and I would like to have a portable application and not to have to set the path of the applications each time I use the application in other computer. My idea is that I expect that the computer has installed the pdf reader and only say what page open.

感谢。

推荐答案

修改(感谢surfbutler评论中问题的评论)
如果你想要的文件与默认的应用程序打开,我的意思是不指定Acrobat或Reader,你不能在指定页面打开该文件。

EDIT (thanks to surfbutler comment in the question comments) If you want the file to be opened with the default application, I mean without specifying Acrobat or Reader, you can't open the file in the specified page.

在另一方面,如果你确定与指定Acrobat或Reader,请继续阅读:

On the other hand, if you are Ok with specifying Acrobat or Reader, keep reading:

的 - ** - ** - ** -

-- ** -- ** -- ** --

您可以不用告诉完全版的Acrobat的路径,例如:

You can do it without telling the full Acrobat path, like this:

Process myProcess = new Process();    
myProcess.StartInfo.FileName = "acroRd32.exe"; //not the full application path
myProcess.StartInfo.Arguments = "/A \"page=2=OpenActions\" C:\\example.pdf";
myProcess.Start();

如果您不希望PDF与阅读器,但使用Acrobat打开,恰克这样第二行:

If you don't want the pdf to open with Reader but with Acrobat, chage the second line like this:

myProcess.StartInfo.FileName = "Acrobat.exe";

第二个编辑:找到的PDF格式扩展名的默认应用程序

您可以查询注册表来确定默认的应用程序来打开PDF文件,然后在你的进程的StartInfo据此定义文件名。 再次感谢surfbutler的评论:)

You can query the registry to identify the default application to open pdf files and then define FileName on your process's StartInfo accordingly. Again, thanks surfbutler for your comment :)

请按照上这样做的细节这个问题:<一href=\"http://stackoverflow.com/questions/162331/finding-the-default-application-for-opening-a-particular-file-type-on-windows\">Finding在Windows

Follow this question for details on doing that: Finding the default application for opening a particular file type on Windows

这篇关于C#打开文件,默认应用程序及参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆