Solved

C# System Cannot Find File Specified Error

Posted on 2016-10-08
4
119 Views
Last Modified: 2016-10-08
I’m trying to write some simple C# code in a winform app that gets the same results as a VB.Net sub. Please help me correct the error. The following VB (in a winform app) code runs without any errors:

Dim retval As String
Dim ls_temp As String
ls_temp = "C:\Program Files (x86)\Visual CUT 11\Visual CUT.exe " & _
"-e ""C:\test\Email_Test_1aa.rpt"""
retval = Shell(ls_temp)


The following C# code results in a "The system cannot find the file specified" error:

using System.Diagnostics;

string retval;
string ls_temp;

retval = "C:\\Program Files (x86)\\Visual CUT 11\\Visual CUT.exe " + "-e " + "C:\\test\\Email_Test_1aa.rpt";

Process runScripts = new Process();
runScripts.StartInfo.FileName = @"""C:\Program Files (x86)\Visual CUT 11Visual CUT.exe""";
runScripts.StartInfo.UseShellExecute = true;
runScripts.StartInfo.RedirectStandardOutput = false;
runScripts.Start();
0
Comment
Question by:Mark01
  • 2
  • 2
4 Comments
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 41835067
aren't you missing a \ on that line:
runScripts.StartInfo.FileName = @"""C:\Program Files (x86)\Visual CUT 11Visual CUT.exe""";

Open in new window


I think it should be:
runScripts.StartInfo.FileName = @"""C:\Program Files (x86)\Visual CUT\11Visual CUT.exe""";

Open in new window

0
 

Author Comment

by:Mark01
ID: 41835109
That resolved the error. The app, Visual Cut, does not perform the desired action, as it does when the VB code is run. All that happens is the following command line runs:
C:\Program Files (x86)\Visual CUT\11Visual CUT.exe

However, the following command line does not run:
C:\\test\\Email_Test_1aa.rpt

Any ideas?
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 41835122
but you never pass your retval to runscripts!

Add this line
runScripts.StartInfo.Arguments = "C:\\test\\Email_Test_1aa.rpt"

Open in new window


Have a look at http://emoreau.com/Entries/Articles/2003/12/The-Process-component.aspx
0
 

Author Closing Comment

by:Mark01
ID: 41835137
Thank you, Eric.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Suggested Solutions

Title # Comments Views Activity
Footer for each row on Gridview 2 30
transaction in asp.net, sql server 6 43
insert value of checklistbox checked 4 32
Finding Events logs for IIS website that restarts 2 14
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…

789 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