Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - Programmatically opening a file in its native program

Reply
 
Old 07-28-2008   #1 (permalink)
Nam


 
 

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

My System SpecsSystem Spec
Old 07-28-2008   #2 (permalink)
Arto Viitanen


 
 

Re: Programmatically opening a file in its native program

Nam wrote:
Quote:

> 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.Diagnostics.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.Diagnostics.Process.Start(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
My System SpecsSystem Spec
Old 07-28-2008   #3 (permalink)
Nam


 
 

Re: Programmatically 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:
Quote:

> Nam wrote:
Quote:

> > 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.Diagnostics.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.Diagnostics.Process.Start(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
>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
programmatically passing network credentials during file IO .NET General
cabview.dll file association (Fix Native Vista Support) Vista General
Re: Opening a PROGRAM???? Vista performance & maintenance
Windows Vista native archiver file tool? Vista General
opening pst file in Outlook 2003 in vista crashes program Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46