Ankita Singh

Ankita Singh

  • NA
  • 159
  • 19k

delete image from folder as like database

Mar 10 2018 12:55 AM
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string id = Request.QueryString["id"].ToString();
imgdltdata(id);
}
}
 
private void imgdltdata(string id)
{
string qry = "delete from appformtbl where id=" + id + "";
DirectoryInfo diInfo = new DirectoryInfo(Server.MapPath("~/Rimage/" + image1.FileName));
FileInfo[] files = diInfo.GetFiles();
for (int i = 0; i < files.Length; i++)
{
string filePath = Server.MapPath("~/Rimage/" + files[i].ToString());
if
(File.Exists(filePath))
{
File.Delete(filePath);
}
}
}
 
this is my code i wanna do that when delete image from database thn also delete from folder.... this code is working but problem is this its delete all image from folder i know problem is in for loop but dont knw how to correct it.... plz someone help me plzzzz...... thanking you.... 

Answers (2)