我在名为Pics ..... Image1.jpg和Image2.jpg的文件夹中有2张图片。

我必须在提交按钮内放置哪些代码才能删除位于此处的Image1.jpg“〜/ Pics / Image1.jpg”

任何帮助都会很棒!!!

有帮助吗?

解决方案

您需要使用 System.IO.File。删除而不是System.IO.Delete

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

其他提示

语法为:

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

但是,您需要确保您的网络应用程序正在运行,因为删除(更改)了您要删除的文件的权限。

试试这个:

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

我会尝试:

String FilePath;
FilePath = Server.MapPath("~/Pics/Image1.jpg");
File.Delete(FilePath);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top