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();
}
}

Suthish NairPosted Jun 18, 2011, 12:20 AM
string userid = Session["UserID"].ToString();
FileInfo[] files = di.GetFiles(userid + "*", SearchOption.TopDirectoryOnly);
You can call me by my name, so no Sir here :)
sagar BhosalePosted Jun 18, 2011, 1:51 AM
Thank you so much for your kind help. It realy helped me a lot in my work.
sagar BhosalePosted Jun 17, 2011, 9:27 PM
1)
FileInfo[] files = di.GetFiles("*.jpg", SearchOption.TopDirectoryOnly); //suppose user added any extenstion image i.e. .png & .gif so how i will write FileInfo[] files
2)
if (item.Name.ToString() == "sagar_abc.jpg") // suppose in my project temp folder suppose sagar_abc.jpg & sagar_cbd.gif images present
so my problem is that how i collect that images according userid i.e. sagar then that images deleted
Sir can we write this in your code
imagepathcollection = allimagepath.Where(img => img.StartWith(userId)); //you will get all images which starts with the userid specified.
can we used search string method to collrect images according to initial name of string i.e. sagar ?
pleas reply me
Suthish NairPosted Jun 17, 2011, 3:32 PM
DirectoryInfo di = new DirectoryInfo(filepath);
FileInfo[] files = di.GetFiles("*.jpg", SearchOption.TopDirectoryOnly);
foreach (FileInfo item in files)
{
//if (item.Name.Split('_')[0].ToString() == "sagar")
if (item.Name.ToString() == "sagar_abc.jpg")
{
if(File.Exists(Path.Combine(filepath, item.Name)))
File.Delete(Path.Combine(filepath, item.Name));
}
}
sagar BhosalePosted Jun 17, 2011, 9:46 AM
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
Jaganathan BantheswaranPosted Jun 17, 2011, 9:17 AM
Are you getting the all image path collection regardless of userid.
if so,
imagepathcollection = allimagepath.Where(img => img.StartWith(userId)); you will get all images which starts with the userid specified.
then delete the files as you did.