从Server中的Server.Mappath中删除文件 [英] Delete file from Server.Mappath in Server

查看:120
本文介绍了从Server中的Server.Mappath中删除文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我在根文件夹中有一个文件列表。我需要从该根文件夹中删除该文件。它在我的本地机器上运行良好。但它显示服务器中的错误。



我使用下面的代码





  string  filePath =(sender  as  LinkBut​​ton).CommandArgument; 
File.Delete(filePath);
Response.Redirect(Request.Url.AbsoluteUri);







请帮帮我从server.mappath删除文件



谢谢

Mohan

解决方案

你应该有权访问服务器和你想要删除文件的文件夹。



您的代码是否在

  string  filePath =(sender  as  LinkBut​​ton).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 above

string 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 and newTempFile is the actual file name eg. "123.xls"


这篇关于从Server中的Server.Mappath中删除文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆