sagar Bhosale

sagar Bhosale

  • NA
  • 179
  • 176k

How to write image path for deleting perticular image stored in temp folder

Jun 16 2011 5:31 AM
e.g. my suppose my image name is  92e95d97-0575-42f6-b08b-8c81a72d0b07_3d-windows-8-wallpaper-ocean--sunset-30--1600-x-1200-jpeg-1280x1024.jpg   
my code below global.asax.cs
protected void Session_End(object sender, EventArgs e) {
string userId = Session["UserId"].ToString();
string path;
string[] filename;

path = System.Web.Hosting.HostingEnvironment.MapPath("~/temp/" +userId);  //i have doubt here how write proper image path

filename = Directory.GetFiles(path);

for (int i = 0; i < filename.Length; i++) {

       if (Session.SessionID == Path.GetFileName(filename[i])) {

              string imgpath = filename[i];

      FileInfo filepath = new FileInfo(imgpath);

               if (filepath.Exists) {

File.Delete(filepath.FullName);

                Session.Abandon();
         
               }

       }
}

}

Answers (2)