Click here to Skip to main content
15,905,420 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I have uploaded some files to my project folder in asp.net and the file path is saved in my database..But when i want to delete that record from the database at that time the related file must be deleted from the project folder..But it is not deleting..Please suggest me...
Posted
Comments
palraj001 10-Jan-12 1:14am    
do you want delete all files?
shek124 10-Jan-12 1:18am    
post your code
Karthik Harve 10-Jan-12 1:25am    
what have you tried.?? show your code..

C#
protected void btnSubmit_Click(object sender, EventArgs e)
{
try {
FileInfo TheFile = new FileInfo(MapPath(".") + "\\" + txtFile.Text);
if (TheFile.Exists) {
File.Delete(MapPath(".") + "\\" + txtFile.Text);
}
else {
throw new FileNotFoundException();
}
}

catch (FileNotFoundException ex) {
lblStatus.Text += ex.Message;
}
catch (Exception ex) {
lblStatus.Text += ex.Message;
}

}
 
Share this answer
 
hi,

files are in images folder.

if Your DB path is like this means

Images\demo.jpg


C#
string dbpath=getdbValue() // get it from DB

string delfile= System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath +dbpath

System.IO.File.Delete(delfile); 







regards,
Pal
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900