ASP.NET - delete image from folder and database

Asked By jyoti yadav on 29-Nov-10 07:18 AM
hello,
how i can delete any image from folder and database in asp.net. if image will delete from database thn it should be delete from folder of aspx page.
well, i hav done coding of delete image from database, but it didnt delete image from folder.it just delete from database not from folder.
reply please.
waiting??
Danasegarane Arunachalam replied to jyoti yadav on 29-Nov-10 07:22 AM
Post your code.
Reena Jain replied to jyoti yadav on 29-Nov-10 07:30 AM
hi,

use the following code

using System.IO; //namespace for file class


use this code after delete from database

  File.Delete(Server.MapPath("images") & "/" & "imagename.jpg")

hope this will help you

jyoti yadav replied to jyoti yadav on 29-Nov-10 07:37 AM
SqlCommand cmd = new SqlCommand("delete from insrt_img where id='" + textbox1.Text + "'");
      cmd.ExecuteNonQuery();

from this code,image can be delete from database.not from folder.
one thing also, i store image url in varchar datatype, not in image datatype.
how i can delete any image from dataabse and folder on a single click.
plz reply.
waiting??
jyoti yadav replied to Reena Jain on 29-Nov-10 07:38 AM
hi reena,
i already tried this code, it gives error, smthng related to & operator.
Reena Jain replied to jyoti yadav on 29-Nov-10 07:41 AM
hi,

this code is for vb.net

  File.Delete(Server.MapPath("images") & "/" & "imagename.jpg")

here is the c#.net code

  File.Delete(Server.MapPath("images/") + "imagename.jpg")

hope this will help you