Solved

Open Text File in Wordpad

Posted on 2009-06-30
13
506 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
 

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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

747 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

11 Experts available now in Live!

Get 1:1 Help Now