473,399 Members | 2,146 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,399 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 6531
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

1
by: John | last post by:
I wrote a MDI application with a CRichEditView. When the user clicks on a button the program displays a dialog box and after the user closes the dialog box the program has to open a new document...
1
by: Alfons | last post by:
Hello, I have build a program that can do file transferring between a Windows XP computer and a DOS computer via a serial port. The Windows program I have build in C++ with Visual Studio 6.0....
28
by: Madhur | last post by:
Hello what about this nice way to open a file in single line rather than using if and else. #include<stdio.h> void main() { FILE *nd; clrscr();...
5
by: Justin Fancy | last post by:
Hi Everyone, I am developing a file aging program that will eventually report on every folder that is in the root directory. I have a list of requested years, and counters set up to count every...
5
by: bimeldip | last post by:
Hi, I an tryin to create a html page where users can choose a file and open it however, i keep getting it wrong.So far this is wat i've worked on: (open.html) <html> <head> <title>Opening...
6
by: shalmi27 | last post by:
hi every1 me new to this forum.... well i really need help... i want a c++ file handling program... for eg: like hotel management,games,railway reservation...... the program..must b able to...
0
by: =?Utf-8?B?Vmlua2k=?= | last post by:
Hello Everyone, I need to open a text file with .net remoting. This text file resides on another server. My server program running on the server has this method that opens the text file...
3
by: sophia | last post by:
Dear all, the following is the file compression program ,using elimination of spaces, which I saw in a book #include<stdio.h> #include<stdlib.h> int main(int argc,char * argv) {
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...
1
by: rcook349 | last post by:
From within my project, I am opening an file elsewhere on the network and changing contents within. When I go to close/save, however, I can't because it's read-only (as it's checked in). Can...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.