Click here to Skip to main content
12,997,042 members (129,492 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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()
               System.Diagnostics.Process.Start("cmd.exe", "/c" + "CapOne.bat");
           catch (Exception ex)
Posted 19-Mar-13 2:27am
@AmitGajjar 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 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 19-Mar-13 9:04am
Use Process.start("Batch file path");

1 solution

Rate this: bad
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

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?


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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170622.1 | Last Updated 19 Mar 2013
Copyright © CodeProject, 1999-2017
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