Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# WCF
Hello everyone,
 
I am working with a batch file in wcf service, batch file is executing properly without any exception or error but actual operation is not done ( moving files from one location to another).
 
This is my code in wcf service.
public void Downloading()
       {
          
           try
           {
               System.Diagnostics.Process.Start("cmd.exe", "/c" + "CapOne.bat");
           }
           catch (Exception ex)
           {
           }
       }
Posted 19-Mar-13 3:27am
Comments
@AmitGajjar at 19-Mar-13 8:37am
   
Check if source and destination directory is exist. You can also use System.IO to move files from one location to another.
Prasad Khandekar at 19-Mar-13 8:40am
   
Hello Bapu,
 
Also verify whether the user account has necessary permissions. I will strongly recommend to follow the Amit's suggestion and use System.IO instead of doing Shell.
vijay79041 at 19-Mar-13 9:04am
   
Use Process.start("Batch file path");

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

First of all, don't use "CMD.EXE". It can work, but makes no sense at all, pure redundant thing. Please use
System.Diagnostics.Process.Start("CapOne.bat");
This along won't make your code working. There can be some other problem. Why do you think that this file is found? It would be found if the calling code has the same working directory as the one where the batch file is located. But you can never guarantee that, as the user can start your application with any working directory, any at all. Did you know that? (Not only a programmer, but every user should understand it.) Instead, you could use your executable directory for a batch file.
 
In the past, I provided two answers comprehensively explaining how to get different paths to be used in an application:
How to find my programs directory ( executable directory),
How to find my programs directory (current directory, "special folders").
 
And of course, you need to make sure the batch file itself is working properly.
 
Finally, the use if the batch file may be the indication of non-programming approach, but the approach of a non-programming user. It looks quite questionable. Why using a batch file? Is it because you don't know how to solve some problem programmatically, so you decided to use available applications? You made them doing the job, and don't want to change anything? How stable would be your result? Maintainable?
 
—SA
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 490
1 Maciej Los 305
2 Richard MacCutchan 270
3 Mathew Soji 220
4 BillWoodruff 210
0 OriginalGriff 8,834
1 Sergey Alexandrovich Kryukov 7,477
2 DamithSL 5,689
3 Maciej Los 5,329
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web02 | 2.8.1411028.1 | Last Updated 19 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100