Wednesday, January 2, 2013

how to delete file from folder in asp.net by FTP


 SqlDataAdapter da = new SqlDataAdapter("Select Path from Table_Image where loginID='" + TxtNo.Text + "'", connection);
        DataSet ds = new DataSet();
        da.Fill(ds);
        if (ds.Tables[0].Rows.Count > 0)
        {
         

            string host = "ftp://"; (Folder Path  Where image save)
            string userName = "uname";            (FTP User Name)
            string pwd = "password";             (FTP Password)
            string fileName = ds.Tables[0].Rows[0]["Path"].ToString();
            fileName = fileName.Replace("url", "");
            string remoteFile = Path.GetFileName(fileName);
            string FTPFilePath = Path.Combine(host, remoteFile);


            FtpWebRequest reqFTP = (FtpWebRequest)WebRequest.Create(FTPFilePath);
            reqFTP.Credentials = new NetworkCredential(userName, pwd);
            reqFTP.KeepAlive = false;
            reqFTP.UseBinary = true;
            reqFTP.UsePassive = false;
       
            reqFTP.Method = WebRequestMethods.Ftp.DeleteFile;

            FtpWebResponse resFTP =(FtpWebResponse)reqFTP.GetResponse();
           string desc=resFTP.StatusDescription;
}

0 comments:

Post a Comment