删除服务器上的文件 [英] Delete file on server
问题描述
我有一个文件路径,格式为 file://SERVERNAME/FOLDER$/FOLDER/image.jpg
。我调用 System.IO.File.Delete(Server.MapPath(file://SERVERNAME/FOLDER$/FOLDER/image.jpg))
删除文件,但是我出现错误 file:/SERVERNAME/FOLDER$/FOLDER/image.jpg'不是有效的虚拟路径。
我注意到缺少'/',但我没有知道为什么。我将如何删除此类文件?
I have a file path in the format file://SERVERNAME/FOLDER$/FOLDER/image.jpg
. I call System.IO.File.Delete(Server.MapPath(file://SERVERNAME/FOLDER$/FOLDER/image.jpg))
to delete the file, but i get the error file:/SERVERNAME/FOLDER$/FOLDER/image.jpg' is not a valid virtual path.
I notice that a '/' is missing and I do not know why. How will I delete such file?
我尝试将文件路径转换为 file://// SERVERNAME // FOLDER $ // FOLDER //image.jpg
,但这没有帮助。同样的事情发生。如果我省略 Server.MapPath
,则会收到一条错误消息,指出不支持URI。
I have tried converting my file path to file:////SERVERNAME//FOLDER$//FOLDER//image.jpg
but this did not help. Same thing happens. If I omit the Server.MapPath
, I get an error saying URI is not supported.
操作方法
推荐答案
因为您正在执行 System.IO.File.Delete
我假设您有权删除该文件;因此您可以:
Since you are doing System.IO.File.Delete
I assume you have the permission to delete the file; so you can:
var uri = new Uri("file://SERVERNAME/FOLDER$/FOLDER/image.jpg", UriKind.Absolute);
System.IO.File.Delete(uri.LocalPath);
这篇关于删除服务器上的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!