VB.NET - Copy files to a network drive

2,516 views
Skip to first unread message

Shibuya

unread,
May 4, 2006, 3:29:41 AM5/4/06
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Hi all, i have a win application that must copy some file on a network
drive.
I cant' simply make something like this:

file.Copy("c:\sample", "\\remote\c$\sample")

because i must use other credentials to access that share.
I think i can use this:
System.Diagnostics.Process.Start("net", "use k: \\remote\c$ Password
/user:domain\administrator")

to map a disk k: and than make a simple copy to k:, but this method is
not cool because it shows the black prompt window while mapping network
dirve.

Someone can suggest me a good method?!

Thanks

Alan

unread,
May 18, 2006, 9:50:04 PM5/18/06
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
I think you try the pipeline
sample code:

Dim p As New Process
p.StartInfo.FileName = "cmd.exe"
p.StartInfo.UseShellExecute = False
p.StartInfo.RedirectStandardInput = True' advert here
p.StartInfo.RedirectStandardOutput = True'advert here
p.StartInfo.RedirectStandardError = True
p.StartInfo.CreateNoWindow = True
p.Start()
p.StandardInput.WriteLine("net use \\192.168.0.3
password/user:administrator")
p.StandardInput.WriteLine("exit")
p.Close()
System.Threading.Thread.CurrentThread.Sleep(4000)
Dim strPathFrom, strPathTo, strGet As String
strPathFrom = "C:\Program Files\PowerTestV3.1-SHT\data"
strPathTo = "\\192.168.0.3\Public1\Test"
strGet = "D:\Public1\Test"


'copy files
Dim strDBArray As String = ""
For Each str As String In dir.GetFiles(strPathFrom)
System.IO.File.Copy(str, strPathTo &
str.Substring(str.LastIndexOf("\")))
strDBArray &= strGet &
str.Substring(str.LastIndexOf("\")) & ","
End If
Next

Reply all
Reply to author
Forward
0 new messages