473,804 Members | 3,220 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Programmaticall y 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 6553
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
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.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
Jul 28 '08 #3

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

Similar topics

1
2552
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 and then write a text string in it. I wrote the following code to do that. void CFormatPlannerView::OnPlaylistGenerate() { CGenerateDlg dlg; if (dlg.DoModal() == IDOK) {
1
4406
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. The DOS program I made in Turbo C++ 3.0. At this moment I am in a test phase of sending files and directories. The code I am using in DOS to open a file for writing looks like this (forgive me the typos, since I only have my source code at work...
28
3285
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(); fopen("c:\\autoexec.bat","r")&&printf("success") || printf("error opeing
5
1578
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 file within every subfolder to add up all the files from the specified year. I have the functionality working, but not quite. With the following code, the end result includes folders within subfolders. For example, instead of having root/folder1/...
5
1985
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 file</title> </head> <body> <form action="display.php" method="POST"> Please choose a file: <input name="saved" type="file" /><br />
6
2109
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 change or del the particular data...given by the user.... plsss...any1..who can help me..plss d help me...
0
1223
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 System.Diagnostics.Process.Start(filePath); My client program has a button which I click and it call the server program method that opens the file. When I click the button, the file opens on the server itself, is it possible that I can see that file...
3
9236
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
1401
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 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
1
4293
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 I just flip read-only off, make my changes and save it, and then flip read only back on (programmatically)? How can I do this, please? Thanks.
0
10588
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10340
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10324
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10085
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7623
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6857
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5662
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4302
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3827
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.