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 NairRank #92 · 22.8K reputationPosted Jun 17, 2011, 8:20 PM EDT
string userid = Session["UserID"].ToString();
FileInfo[] files = di.GetFiles(userid + "*", SearchOption.TopDirectoryOnly);
You can call me by my name, so no Sir here :)
Jaganathan BantheswaranRank #170 · 14.1K reputationPosted Jun 17, 2011, 5:17 AM EDT
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.
sagar Bhosale162 reputationPosted Jun 17, 2011, 5:46 AM EDT
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
Suthish NairRank #92 · 22.8K reputationPosted Jun 17, 2011, 11:32 AM EDT
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 Bhosale162 reputationPosted Jun 17, 2011, 5:27 PM EDT
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
sagar Bhosale162 reputationPosted Jun 17, 2011, 9:51 PM EDT
Thank you so much for your kind help. It realy helped me a lot in my work.