473,326 Members | 2,126 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,326 software developers and data experts.

Can you open a notepad txt file from c# code?

Basically I want to know how you could open a txt file in notepad through c#
code. I don't want to read in the data or anything like that I just want to
open the file just as it would have been if you double clicked it. Doesn't
necessarily have to be notepad I might add. Any suggestions? Thanks a bunch.
Ken
Nov 16 '05 #1
3 19114
Ken Adams wrote:
Basically I want to know how you could open a txt file in notepad
through c# code. I don't want to read in the data or anything like
that I just want to open the file just as it would have been if you
double clicked it. Doesn't necessarily have to be notepad I might
add. Any suggestions? Thanks a bunch.

Ken


What you are talking about is writing your own WinForm Notepad application
from scratch. you'd want to have the Main() method command-line argument
read in the file and then you'd open it using a FileStream object, and then
render it in a window however you want.
Nov 16 '05 #2
If you really want to handle it this way you should look at starting a
process using something like:

System.Diagnostics.Process.Start("notepad.exe", @"C:\temp\TheFile.txt");

The first parameter is the name of the application you want to launch
while the second is the parameters you want to send to it. In this case
notepad accepts the name of a file to open. Anyway it should accomplish
what you asked for.

Have A Better One!

John M Deal, MCP
Necessity Software

Ken Adams wrote:
Basically I want to know how you could open a txt file in notepad through c#
code. I don't want to read in the data or anything like that I just want to
open the file just as it would have been if you double clicked it. Doesn't
necessarily have to be notepad I might add. Any suggestions? Thanks a bunch.
Ken

Nov 16 '05 #3
If the .txt extension is associated with Notepad, you can simply call this:

System.Diagnostics.Process.Start("YourFile.txt");

Note that this will work with any extension. This is like ShellExecute in
Win32.

--
Ajay Kalra [MVP - VC++]
aj*******@yahoo.com
"Ken Adams" <ho*********@hotmail.com> wrote in message
news:DU5sd.40022$VL6.33032@clgrps13...
Basically I want to know how you could open a txt file in notepad through c# code. I don't want to read in the data or anything like that I just want to open the file just as it would have been if you double clicked it. Doesn't
necessarily have to be notepad I might add. Any suggestions? Thanks a bunch.

Ken

Nov 16 '05 #4

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

Similar topics

4
by: Jesper | last post by:
How can I open a textfile from C# using notepad (or the user assigned application for this).
7
by: Hareth | last post by:
When VS2003 is installed : I can open Form1.cs w/ windows "open with" contextmenu, then it opens the file w/ notepad & it works fine but after installing VS2005, "open with" doesnt...
2
by: preetish | last post by:
Hi, I am a total novice to VC++..I have a dialog based application developed using MFC...my requirement is to open a file (with .dat or ..txt ext) invoking Notepad from my application. The user...
3
by: RN Das | last post by:
Hi expert, I have a small web application in C# and ASP.Net and I want to open a file in notepad when clicked on a linked button. Here is hander code when clicked on the link button. It can open...
7
by: Lumpierbritches | last post by:
Thank you in advance for any and all assistance. It is greatly appreciated. I would like a command button in VB.Net 2002 to open a text file, then to allow text from a textbox on the current form...
2
by: Seok Bee | last post by:
Dear Experts, In my web application, I am having a button to open a file located in the server. When I click on the button to view the file, I received the following error message:...
6
by: Moumen VB.NET 2003/2005 Developer | last post by:
How can I detect if a file sitting on a network drive is still open by another application? This application resides on another machine on the network? I am using VB.NET 2003 Your help is...
5
by: Ryan Liu | last post by:
Hi, Both way works, I'd just ask some experts which way is better? My application creates a log file daily. Now each time when I write a log, I will open the file and append to the end....
25
by: stefbek97 | last post by:
Hello All, I am having a bit of trouble opening a file in my ASP.Net/C# Application. I have a file Path and name stored in my Database. I display that filename in a Gridview control. I also have a...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.