Solved

C# System Cannot Find File Specified Error

Posted on 2016-10-08
4
55 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 69

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 69

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

705 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

18 Experts available now in Live!

Get 1:1 Help Now