c# open file with default application and parameters
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.
On the other hand, if you are Ok with specifying Acrobat or Reader, keep reading:
You can do it without telling the full Acrobat path, like this:
using 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();
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";
You can query the registry to identify the default application to open pdf files and then define FileName on your process's StartInfo accordingly.
Follow this question for details on doing that: Finding the default application for opening a particular file type on Windows
C# Open File With Associated Application passing arguments
I believe this is expected. Behind the scenes, Windows is finding the default application in the registry and creating a new process and passing your file name to it. I get the same behavior if I go to a command prompt and type "filename.ext argument", that my arguments are not passed to the application.
What you probably need to do is find the default application yourself by looking in the registry. Then you can start that process with arguments, instead of trying to start by filetype association. There is an answer here on how to find the default application in the registry:
Finding the default application for opening a particular file type on Windows
Open file with associated application
Just write
System.Diagnostics.Process.Start(@"file path");
example
System.Diagnostics.Process.Start(@"C:\foo.jpg");
System.Diagnostics.Process.Start(@"C:\foo.doc");
System.Diagnostics.Process.Start(@"C:\foo.dxf");
...
And shell will run associated program reading it from the registry, like usual double click does.
How to launch default application for an arbitrary file in .net?
Just use Process.Start
(MSDN-article)
Process.Start(pathToYourFile);
Windows will launch the appropriate application. Just watch out: Up until Windows 8, this will throw an exception, if there is no standard application for that file type.
Open a file not using default program
You can use the System.Diagnostics.Process(String, String)
method that you can find further documentation here
Sample:
// Start a Web page using a browser associated with .html and .asp files.
Process.Start("IExplore.exe", "C:\\myPath\\myFile.htm");
For future posts, I suggest you post code that you have already attempted/written to help us better help you.
Open file with application
So here is what I did:
I made my own file extension .xxx (inside there is just plain xml) when I open it with my application I check in constructor of startup window for the parameters count using the
Environment.GetCommandLineArgs()
If count > 1 I get the second parameter which is string with absolute path to the file. Then I fetch the string to the method handling the opening of the file.
Related Topics
Declaration Suffix for Decimal Type
Web API How to Add a Header Parameter for All API in Swagger
How to Disable a Tab Inside a Tabcontrol
How to Set Timer Resolution from C# to 1 Ms
Are There Any Suggestions for Developing a C# Coding Standards/Best Practices Document
Fast and Compact Object Serialization in .Net
How to Retrieve Data from a SQL Server Database in C#
Getting Day Suffix When Using Datetime.Tostring()
What Is Point of Ssl If Fiddler 2 Can Decrypt All Calls Over Https
How to Read Data from a Zip File Without Having to Unzip the Entire File
Most Efficient Way to Insert Rows into MySQL Database
How to Change Symbol for Decimal Point in Double.Tostring()
How to Run Visual Studio Without Plugin and All Third Party Feature
The Maximum Number of Characters a Textbox Can Display
What Are the Benefits of Using C# VS F# or F# VS C#
How to Read Values from the Querystring with ASP.NET Core
Using Process.Start() to Start a Process as a Different User from Within a Windows Service