Click here to Skip to main content
15,920,636 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Delete file from my website by asp.net(c#)
Hi
How can I Delete a file from my website by asp.net(c#)
Thanks very much
Posted

1 solution

Try this on button click event:

C#
using System.IO// add the namesapce

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

}


hope it helps :)
 
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