Open File With Associated Application [C#]
This example demonstrates how to open file with an associated program. It shows, how to open text document in notepad, how to open image in a default viewer or how to open url address in a default web browser.
Applications are launched using Process.Start method. The file path or url is passed as a parameter.
[C#]// open text file in notepad (or another default text editor) System.Diagnostics.Process.Start(@"c:\textfile.txt");[C#]
// open image in default viewer System.Diagnostics.Process.Start(@"c:\image.jpg");[C#]
// open url in default web browser System.Diagnostics.Process.Start("https://www.csharp-examples.net");[C#]
// open PDF file System.Diagnostics.Process.Start(@"c:\document.pdf");
Similarly you can open Word document or any other file from your .NET application.
Files and Folders Examples
- [C#] FileStream Open File – how to open file using file stream
- [C#] FileStream Read File – how to safely read file stream
- [C#] Read Text File – how to read lines from text file
- [C#] Load Text File to String – how to load text from file to string
- [C#] Get Files from Directory – how to get files from directory
- [C#] Delete All Files – how to delete files from the specified directory
- [C#] Get Application Directory – how to get application or assembly folder
- [C#] File Attributes – how to get or set file attributes
- [C#] Get File Time – how to get last modification time of a file
- [C#] Open File With Associated Application – how to launch the default application
See also
- Process.Start – MSDN – method to start a process