Solved

Open Text File in Wordpad

Posted on 2009-06-30
13
511 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

856 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