Using WScript.Shell to copy a file on the server.
-
Hello, I would like to copy a particular file from one place on the server to another in an ASP.NET code behind page using c#. I know it can be done using vbscript with something similar to the following code: SET oShell = Server.CreateObject( "WScript.Shell" ) cmd = "cmd.exe /c copy " & originalPath & " " & destinationPath rval = oShell.Run (cmd,0,TRUE) SET oShell = Nothing I don't actually know what WScript is or does (haven't found a lot of documentation on it). When I try similar code in c#, it says I'm missing a directive. Does anyone know how to use WScript.Shell with c#? Or, is there a better way to accomplish this with out using WScript.Shell at all? Thanks for your help, RC
-
Hello, I would like to copy a particular file from one place on the server to another in an ASP.NET code behind page using c#. I know it can be done using vbscript with something similar to the following code: SET oShell = Server.CreateObject( "WScript.Shell" ) cmd = "cmd.exe /c copy " & originalPath & " " & destinationPath rval = oShell.Run (cmd,0,TRUE) SET oShell = Nothing I don't actually know what WScript is or does (haven't found a lot of documentation on it). When I try similar code in c#, it says I'm missing a directive. Does anyone know how to use WScript.Shell with c#? Or, is there a better way to accomplish this with out using WScript.Shell at all? Thanks for your help, RC
Why do you even want to use WScript? Just use the classes in
System.IO
. You can copy, create, delete, move etc. files and folders. regards, Paul Watson Bluegrass South Africa Anna-Jayne Metcalfe wrote: "Cynicism has it's place in life - but it should be kept well away from your inner self." Crikey! ain't life grand? -
Why do you even want to use WScript? Just use the classes in
System.IO
. You can copy, create, delete, move etc. files and folders. regards, Paul Watson Bluegrass South Africa Anna-Jayne Metcalfe wrote: "Cynicism has it's place in life - but it should be kept well away from your inner self." Crikey! ain't life grand?Hi, I'm still rather new to .NET so I didn't know that System.IO had all of these functions. I tried System.IO.Directory.Move(file1,file2) and it worked like a charm. Thanks for your help!! RC
-
Hi, I'm still rather new to .NET so I didn't know that System.IO had all of these functions. I tried System.IO.Directory.Move(file1,file2) and it worked like a charm. Thanks for your help!! RC
Cool chubbysilk, glad I could help. Another tip is to put a
Using System.IO;
at the top of your CS file and then you can just useDirectory.Move(file1,file2);
without the namespace reference. regards, Paul Watson Bluegrass South Africa Anna-Jayne Metcalfe wrote: "Cynicism has it's place in life - but it should be kept well away from your inner self." Crikey! ain't life grand? -
Cool chubbysilk, glad I could help. Another tip is to put a
Using System.IO;
at the top of your CS file and then you can just useDirectory.Move(file1,file2);
without the namespace reference. regards, Paul Watson Bluegrass South Africa Anna-Jayne Metcalfe wrote: "Cynicism has it's place in life - but it should be kept well away from your inner self." Crikey! ain't life grand?Hi, I just ran into one small problem. The System.IO.Directory.Move function works when I copy a file from one folder to another on a single drive. But I am unable to copy a file from the C drive to the E drive. Do you know how to get around that? Thanks again, RC
-
Cool chubbysilk, glad I could help. Another tip is to put a
Using System.IO;
at the top of your CS file and then you can just useDirectory.Move(file1,file2);
without the namespace reference. regards, Paul Watson Bluegrass South Africa Anna-Jayne Metcalfe wrote: "Cynicism has it's place in life - but it should be kept well away from your inner self." Crikey! ain't life grand?