Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

C# System Cannot Find File Specified Error

Posted on 2016-10-08
4
Medium Priority
?
356 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

661 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