Question

I have 2 images inside a folder called Pics..... Image1.jpg and Image2.jpg.

What code must i place inside my Submit button to just delete Image1.jpg located here "~/Pics/Image1.jpg"

Any help would be great!!!

Was it helpful?

Solution

You need to use System.IO.File.Delete not System.IO.Delete

string path = "~/Pics/Image1.jpg";
System.IO.File.Delete(Server.MapPath(path))

OTHER TIPS

The syntax is:

System.IO.File.Delete(Server.MapPath("~/Pics/Image1.jpg"));

You will need to make sure the user your web app is running as has delete (change) permissions on the file you are deleting, however.

Try This:

String FileName = "Image1.jpg";
System.IO.File.Delete(Server.MapPath(("~/Pics/") + FileName));

i would try:

String FilePath;
FilePath = Server.MapPath("~/Pics/Image1.jpg");
File.Delete(FilePath);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top