Solved

C# System Cannot Find File Specified Error

Posted on 2016-10-08
4
253 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
[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
  • 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

A new era in Cloud training has arrived.

A day that will go down in Cloud history.. But are you ready for it? Will you accept this Cloud challenge?

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

615 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