Establish network connection

//開始網路連線
System.Diagnostics.ProcessStartInfo psInfo = new System.Diagnostics.ProcessStartInfo(@”C:\WINDOWS\system32\net.exe”);
psInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
psInfo.Arguments = @”net use \\192.168.0.15\RD$ ams.prog /user:programw”; //輸入相關資訊
System.Diagnostics.Process.Start(psInfo);

Anuncios

Check if a FTP connection is valid

private bool isValidConnection (string url, string user, string password){

try{

FtpWebRequest request = (FtpWebRequest) WebRequest.Create(url);

request.Method = WebRequestMethods.Ftp.ListDirectory;

request.Credentials = new NetworkCredential (user, password);

request.GetResponse();

}

catch (WebException ex){

return false;

}

return true;

}

*ftp format-> ftp://ip/directory

Get ConnectionString from App.config

Dim connections As ConnectionStringSettingsCollection = ConfigurationManager.ConnectionStrings

If connections.Count <> 0 Then

For Each connection As ConnectionStringSettings In connections

Dim name As String = connection.Name

Dim provider As String = connection.ProviderName

Dim connectionString As String = connection.ConnectionString

Next

Else

End If