?
Solved

Open Text File in Wordpad

Posted on 2009-06-30
13
Medium Priority
?
517 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month11 days, 13 hours left to enroll

752 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