Articles in categories

Articles

Open files with their default application in C#

Open files with their default application in C#

      // open text file in default text editor
      Process.Start(@"c:\test.txt");

      // open url in default web browser
      Process.Start("http://www.stievens-corner.be");

      // open pdf file
      Process.Start(@"c:\test.pdf");

      // open doc or docx file
      Process.Start(@"c:\test.doc");
      Process.Start(@"c:\test.docx");

      // open xls or xlsx file
      Process.Start(@"c:\test.xls");
      Process.Start(@"c:\test.xlsx");

      // open jpg or png image in default imageviewer
      Process.Start(@"c:\image.jpg");
      Process.Start(@"c:\image.png");

      // open default web browser with Google search page and parameter
      string s = "stievens corner";
      Process.Start("http://google.com/search?q=" + s);

      // open a program
      ProcessStartInfo startInfo = new ProcessStartInfo();
      startInfo.FileName = "WINWORD.EXE";
      Process.Start(startInfo);