Click here to Skip to main content
15,881,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.
C#
public void Downloading()
       {
          
           try
           {
               System.Diagnostics.Process.Start("cmd.exe", "/c" + "CapOne.bat");
           }
           catch (Exception ex)
           {
           }
       }
Posted
Comments
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

First of all, don't use "CMD.EXE". It can work, but makes no sense at all, pure redundant thing. Please use
C#
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
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900