Using System.IO.Delete to delete specific files from a directory?

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

What code should I put inside my Submit button to just delete Image1.jpg located here "~ / Pics / Image1.jpg"

Any help would be great !!!

+3
source share
4 answers

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

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

Syntax:

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

, -, () , .

+3

Try the following:

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

I would try:

String FilePath;
FilePath = Server.MapPath("~/Pics/Image1.jpg");
File.Delete(FilePath);
0
source

Source: https://habr.com/ru/post/1707500/


All Articles