Sunday, April 26, 2009

Upload files on Secure FTP

hi friends
i am having trouble with the Secure ftp site. i was not able to upload the files on the secure ftp site using my code. the code works good if the ftp site don't have the Secure SSI connection. then i have written a code which uses FtpWebRequest for uploading the data on secure ftp site. In this code i have one problem about the Certificates which should be issued in order to make it secure sit. i don't have that certificates so i have written a static method which will make the certification value as valid in any case. here is the code. hope it will help you guys
public bool SecureConnection(string UrlPath, string UserName, string Password,string command,string filePath,string fileName) { try { //String serverUri = "ftp://ftpsite.com/folder1/Test"; if (command.Equals("UF")) UrlPath = UrlPath + "//" + fileName; //String serverUri =UrlPath; FtpWebRequest request = (FtpWebRequest)WebRequest.Create(UrlPath); request.Credentials = new NetworkCredential(UserName, Password); request.UsePassive = true; request.EnableSsl = true; switch (command) { case "MD": if(SecureConnectionRemoveDirectory(UrlPath,UserName,Password)) request.Method = WebRequestMethods.Ftp.MakeDirectory; break; case "UF": request.Method = WebRequestMethods.Ftp.UploadFile; StreamReader sourceStream = new StreamReader(filePath); byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd()); sourceStream.Close(); request.ContentLength = fileContents.Length; Stream requestStream = request.GetRequestStream(); requestStream.Write(fileContents, 0, fileContents.Length); requestStream.Close(); break; } ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(ValidateServerCertificate); FtpWebResponse response = (FtpWebResponse)request.GetResponse(); } catch (Exception _exp) { return false; } return true; } public static bool ValidateServerCertificate(object sender,X509Certificate certificate, X509Chain chain,SslPolicyErrors sslPolicyErrors) { return true; }

Tuesday, April 21, 2009

Finding Number of Rows in UltraGrid

Hi friends
Today i was working on Ultra Grid provided by
Infragistics. I found out a typical problem. There is a scenario where i have to find the number of rows selected in the grid. These number of rows are not by selecting the check boxes in the grid cell but by CTR-Click combination. i can check the activated row by the active index properties but now i have to select all the rows which i have previously selected with the holding the control button. Below is the code which might be helpful for you.


public ArrayList GetSelectedAccount(Infragistics.Win.UltraWinGrid.UltraGrid dgAccount)
{
ArrayList AccountArray = new ArrayList();
CurrencyManager cmAccount = (CurrencyManager)this.BindingContext [dgAccount.DataSource, dgAccount.DataMember];
DataView dvAccount = (DataView)cmAccount .List;
for (int i = 0; i < dvAccount .Count; ++i)
{
if (dgAccount.Rows[i].Selected)
{
AccountArray.Add(dgAccount.Rows[i].Cells["AccountID"]);
}
}
messagebox.show(AccountArray.length.tostring());
}
[/CODE]