Programmatically opening a file in its native program

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?TmFt?=

    Programmatically opening a file in its native program

    Version: .NET Framework 2.0

    In my Windows Forms application, how can I open a file in its native
    program?. Let’s say a listbox displays a list of file names with full paths;
    when a user double clicks on a file name, the file opens in its native
    program, a Word document opens in a Word Application, an HTML file opens in
    IE etc. etc. Much like search result pane of Windows Explorer Search utility.

    Thank you
  • Arto Viitanen

    #2
    Re: Programmaticall y opening a file in its native program

    Nam wrote:
    Version: .NET Framework 2.0
    >
    In my Windows Forms application, how can I open a file in its native
    program?. Let’s say a listbox displays a list of file names with full paths;
    when a user double clicks on a file name, the file opens in its native
    program, a Word document opens in a Word Application, an HTML file opens in
    IE etc. etc. Much like search result pane of Windows Explorer Search utility.
    >
    Thank you
    System.Diagnost ics.Process has method Start, that "Starts a process
    resource by specifying the name of a document or application file and
    associates the resource with a new Process component.".

    Following code works fine:


    OpenFileDialog ofd = new OpenFileDialog( );
    if (ofd.ShowDialog () == DialogResult.OK )
    System.Diagnost ics.Process.Sta rt(ofd.FileName );

    The file open dialog shows, and when the user selects a file, and
    clicks open, the file is opened on its associated program.

    --
    Arto Viitanen

    Comment

    • =?Utf-8?B?TmFt?=

      #3
      Re: Programmaticall y opening a file in its native program

      Arto,
      Thank you very much. You explained it very well and your example was very
      easy to understand.

      Nam

      "Arto Viitanen" wrote:
      Nam wrote:
      Version: .NET Framework 2.0

      In my Windows Forms application, how can I open a file in its native
      program?. Let’s say a listbox displays a list of file names with full paths;
      when a user double clicks on a file name, the file opens in its native
      program, a Word document opens in a Word Application, an HTML file opens in
      IE etc. etc. Much like search result pane of Windows Explorer Search utility.

      Thank you
      >
      System.Diagnost ics.Process has method Start, that "Starts a process
      resource by specifying the name of a document or application file and
      associates the resource with a new Process component.".
      >
      Following code works fine:
      >
      >
      OpenFileDialog ofd = new OpenFileDialog( );
      if (ofd.ShowDialog () == DialogResult.OK )
      System.Diagnost ics.Process.Sta rt(ofd.FileName );
      >
      The file open dialog shows, and when the user selects a file, and
      clicks open, the file is opened on its associated program.
      >
      --
      Arto Viitanen
      >

      Comment

      Working...