Solved

Open Text File in Wordpad

Posted on 2009-06-30
13
510 Views
Last Modified: 2012-05-07
How can I open a text file via Wordpad in C#.  The code I'm using below compiles fine, but nothing happens when I attempt to launch Wordpad.
string strLogFilePath = @"c:\dir\subdir\file.txt";
System.Diagnostics.Process process = new System.Diagnostics.Process();
process = System.Diagnostics.Process.Start("wordpad", strLogFilePath);

Open in new window

0
Comment
Question by:thegreekitalian
  • 5
  • 4
13 Comments
 
LVL 5

Expert Comment

by:iUsername
ID: 24749681
What happens if you run:

System.Diagnostics.Process.Start(@"C:\Program Files\Windows NT\Accessories\wordpad.exe", strLogFilePath);

???
0
 
LVL 39

Expert Comment

by:abel
ID: 24749700
you do not need your line 2, that a redundant "new" statement.

Just tried your code, works perfect for me. What errors do you get?
0
 

Author Comment

by:thegreekitalian
ID: 24749763
abel,
I don't get an error, I get nothing at all.
private void viewLogToolStripMenuItem_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("wordpad", strLogFilePath);
        }

Open in new window

0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

Author Comment

by:thegreekitalian
ID: 24749770
iUsername,

The same thing happens... which is absolutely nothing.
0
 
LVL 39

Expert Comment

by:abel
ID: 24749794
Just as experiment, can you past the following line and execute it from the immediate window to see if that works (it doesn't matter that the file does not exist)?

System.Diagnostics.Process.Start("wordpad", "test.txt");

(for the immediate window to work, your application must be error free and have the Startup focus).

When that works, can you place a breakpoint on line 3 in your last post and run your application? When it hits the breakpoint, can you copy the line from the breakpoint line in the imm. window and execute it (hit enter)? If that works, can you hit F10 to go to the next line? If that works.... (but it shouldn't, let's see how far you get).
0
 
LVL 39

Expert Comment

by:abel
ID: 24749811
PS: if wordpad could not be found or started (just tested that), you will get an exception.
0
 

Accepted Solution

by:
thegreekitalian earned 0 total points
ID: 24750096
Still not working.  Tired of messing with it.  I just created a multi-line text box control that I'll read the log file into.  Thanks for your help.
0
 
LVL 39

Expert Comment

by:abel
ID: 24750241
If you're running on Vista and you are not an administrator, you may've run into user-restriction problems. Also, does the breakpoint hit and what did the imm. window output? It should dump about 100 lines of useful information....

Oh, and have you already checked the task manager? And what happens if you go to a command window and type "start wordpad"? That uses the same command internally as Process.Start.

Well, if you don't want to pursue this further....
0
 

Author Comment

by:thegreekitalian
ID: 24750510
abel,

I already went ahead with the text box.  I appreciate your help, though.  Thank you.
0
 
LVL 39

Expert Comment

by:abel
ID: 25438308
Not sure why "a full refund" as the asker clearly answered this question himself: he went for another solution. This (s)he explains in http:#24750096 along with giving the other solution. My suggestion/request is to accept his comment as answer.

The question is valuable to keep because the other comments give insight in how to troubleshoot the original problem.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Vb.net dynamic formulas in runtime 11 74
how can i get the executable application's path in a specific form? ('\\' instead of '\ ') 5 38
Hey!! 5 33
C# bracket error 3 30
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now