I wanna know how to copy file to network folder.
For example
string sourceFile = @"c:\test.txt"
string destFile = @"\\servername\sharefolder"
FileInfo sourceFile = new FileInfo(sourceFilename)
FileInfo destFile = new FileInfo(destFilename)
sourceFile.CopyTo(destFilename, true)
In this case, I wanna how to process inputing ID & PWD in source code
thanks!
DotNetJunkies User - 19 Oct 2004 18:29 GMT
To copy a file to a network share folder, you must make a connection first. For making a connection simple use the following function. Note that you have to add a reference to 'system.management' first. Also, you should add the line 'Imports System.Management' to your code.
Private Function ConnectToServer(ByVal Host As String, ByVal User As String, ByVal Password As String) As Boolean
Dim Scope As Management.ManagementScope
Dim Options As Management.ConnectionOptions
Options = New ConnectionOptions
Options.Username = Host & "\" & User
Options.Password = Password
Try
Scope = New ManagementScope("\\" & Host & "\root\cimv2", Options)
Scope.Connect()
If Scope.IsConnected Then
Return True
Else
Return False
End If
Catch ex As Exception
Return False
End Try
End Function
---