从Server中的Server.Mappath中删除文件 [英] Delete file from Server.Mappath in Server
问题描述
大家好,
我在根文件夹中有一个文件列表。我需要从该根文件夹中删除该文件。它在我的本地机器上运行良好。但它显示服务器中的错误。
我使用下面的代码
string filePath =(sender as LinkButton).CommandArgument;
File.Delete(filePath);
Response.Redirect(Request.Url.AbsoluteUri);
请帮帮我从server.mappath删除文件
谢谢
Mohan
你应该有权访问服务器和你想要删除文件的文件夹。
您的代码是否在string filePath =(sender as LinkButton).CommandArgument;
返回文件的正确路径?
必须匹配以下
文件。删除(Server.MapPath( 〜/ temp /)+ newTempFile)
其中〜/ temp /
是根文件夹中的子文件夹,包含要删除的所有文件和newTempFile
是实际的文件名,例如。123.xls
Hi All,
I have a list of files in root folder. I need to delete the file from that root folder. Its working fine in my local machine. But it shows error in server .
I use the below code
string filePath = (sender as LinkButton).CommandArgument;
File.Delete(filePath);
Response.Redirect(Request.Url.AbsoluteUri);
Please help me to delete file from server.mappath
Thanks
Mohan
You should have access on the server and the folder in which you would want to delete the files from.
Does your code abovestring filePath = (sender as LinkButton).CommandArgument;
return the right path of the file?
It has to match the below
File.Delete(Server.MapPath("~/temp/") + newTempFile)
where"~/temp/"
is the sub-folder within the root folder that has all the files to delete andnewTempFile
is the actual file name eg."123.xls"
这篇关于从Server中的Server.Mappath中删除文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!