473,378 Members | 1,395 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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
Jul 28 '08 #1
2 1371
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.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
Jul 28 '08 #2
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.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
Jul 28 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Prakash Wadhwani | last post by:
I have an Access Database called "TEMP" On Opening the "TEMP" Database, I need to use VBA (programmatically): a) to connect to another database called "PMF" b) the PMF database requires a...
13
by: Alexandra | last post by:
Hi, I have a hidden system file that I need to read. I am logged in as an administrator. I can not change the file attributes using the windows explorer.
11
by: aldrin | last post by:
I'm trying to run this code under windows xp sp2 using codeblocks v1.0 compiler with great difficulty.There is no problem with running this under KDevelop in linux. Any help would be greatly...
11
by: Lee Crabtree | last post by:
I've got a solution that has a C++ project that compiles to a DLL, and a C# project that is the main piece of the program. The DLL is managed C++ on top of regular C++. In one of the native...
2
by: mravichandran | last post by:
dear Readers, i will be downloading a zip file from the intranet website programmatically and i would like to process some of the files inside them before the user can save it. we have a lot of...
0
by: Paulson | last post by:
Dear Freinds I want to make a program that acts as a reminder for the users.I need to open up the Scheduled task wizard programmatically.If you type Tasks in the run command the Tasks...
11
by: =?Utf-8?B?UGV0ZXIgSw==?= | last post by:
I am working with Visual Studio or alternately with Expression Web. I need to create about 50 aspx pages with about 1200 thumbnali images, typically arranged in three to four groups per page,...
2
by: =?Utf-8?B?TmFt?= | last post by:
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...
8
by: K Viltersten | last post by:
I understand that the new versions of MS Word, MS Excel etc. allow for creation of a document using XML tags (the technique or format is called OOXML, i think). I imagine that the idea behind...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.