c#打开具有默认应用程序和参数的文件 [英] c# open file with default application and parameters

查看:1614
本文介绍了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();

如果您不希望使用Reader打开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上定义FileName。 再次感谢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 :)

关于这样做的细节,请关注此问题:查找在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天全站免登陆