使用 System.IO.Delete 从目录中删除某些文件?

发布于 2024-07-18 18:21:28 字数 143 浏览 5 评论 0原文

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

我必须在提交按钮中放置什么代码才能删除位于此处“~/Pics/Image1.jpg”的 Image1.jpg

任何帮助都会很棒!

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!!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

瑾夏年华 2024-07-25 18:21:28

您需要使用 System.IO.File.Delete 不是 System.IO.Delete

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

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

string path = "~/Pics/Image1.jpg";
System.IO.File.Delete(Server.MapPath(path))
疏忽 2024-07-25 18:21:28

语法是:

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

但是,您需要确保您的 Web 应用程序正在运行的用户对您要删除的文件具有删除(更改)权限。

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.

找个人就嫁了吧 2024-07-25 18:21:28

尝试这个:

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

Try This:

String FileName = "Image1.jpg";
System.IO.File.Delete(Server.MapPath(("~/Pics/") + FileName));
静赏你的温柔 2024-07-25 18:21:28

我会尝试:

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

i would try:

String FilePath;
FilePath = Server.MapPath("~/Pics/Image1.jpg");
File.Delete(FilePath);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文