Copy the file to another computer using cmd in C #

I want to copy a picture to the homegroup shared folder. I opened cmd.exe through the Start menu> Run> cmd.exe and typed:

copy C:\pic1.png \\SOMECOMP\Users\SOMEONE\Shared

Image was copied well. However, when I try to do the same with C #, like this:

System.Diagnostics.Process.Start(@"cmd.exe", @"/c start copy C:\pic1.png \\SOMECOMP\Users\SOMEONE\Shared");

I get the following message:

Access is denied.

How can i fix this?

PS - File.Copy produces the same error. For me, the cmd method looked more promising.

+3
source share
2 answers

Why don't you use Process.Start to copy files if File.Copy ?

File.Copy(@"C:\pic1.png", @"\\SOMECOMP\Users\SOMEONE\Shared\pic1.png", true);

, , , , UNC-, , ASP.NET Windows NT, .

+5

,

& "net" "use" "$mapdrive" "$password" "/USER:$username"
& "copy" $src "$dest"
& "net" "use" $mapdrive "/delete"

, , System.IO.File .

0

Source: https://habr.com/ru/post/1786957/


All Articles