6
Answers

How to delete image according to intial string of the images

sagar Bhosale

sagar Bhosale

13y
2.3k
1
Hi friend,  i have one problem that in my project temp folder where i upload images according userid  so images is uploaded in temp folder in this manner userid_abc.jpg in this format 
so my problem is that how to delete that images according that userid  

using foreach loop how i collect images according to userid then matching that userid how i will delete images pleaz help me i very trouble to find out solution

i want to my  code in above format how can i do this pleaz help me
my code is global.asax.cs

protected void Session_End(object sender, EventArgs e) {
string userId = Session["UserId"].ToString();
string path;
string ImagePath =Session["Imagepath"].ToString();

path = System.Web.Hosting.HostingEnvironment.MapPath("~/temp/" + userId + "_" + ImagePath);

      FileInfo filepath = new FileInfo(path);

               if (filepath.Exists) {

File.Delete(filepath.FullName);

                Session.Abandon();
         
               }

       }

Answers (6)