日期:2014-05-17  浏览次数:21009 次

删除URL路径下的文件,在线等
路径:"http://IP地址/文件夹名/文件" 
在网上查了一些方法,但都会报错"URL格式不支持",谁来帮帮忙
十分感谢
------最佳解决方案--------------------
string allfile = "http://IP地址/文件夹名/文件";//存放文件                 
if (File.Exists(rarinfo))
{
          File.Delete(rarinfo); //删除
}
------其他解决方案--------------------
转为相对路径,然后用server.mappath
------其他解决方案--------------------
//URL相对路径转换成服务器绝对路径      
private string urlconvertorlocal(string imagesurl1)  
{  
    //获取程序根目录  
    string tmpRootDir = Server.MapPath(System.Web.HttpContext.Current.Request.ApplicationPath.ToString());  
    //转换成服务器绝对路径  
    string imagesurl2 = tmpRootDir + imagesurl1.Replace(@"/", @"/");   
    return imagesurl2;  
}  
------其他解决方案--------------------
string aa = "http://IP地址/文件夹名/文件";
string strFilePath = aa.Replace("http://", "");
if (File.Exists(strFilePath))
{
File.Delete(strFilePath);
if (!File.Exists(strFilePath))
{
Response.Write("ok");
}
else
{
Response.Write("no");
}

}
------其他解决方案--------------------
引用:
string allfile = "http://IP地址/文件夹名/文件";//存放文件                 
if (File.Exists(rarinfo))
{
          File.Delete(rarinfo); //删除
}

这样试过了,File.Exists(rarinfo)找不到文件,永远是false
------其他解决方案--------------------
引用:
string allfile = "http://IP地址/文件夹名/文件";//存放文件                 
if (File.Exists(rarinfo))
{
          File.Delete(rarinfo); //删除
}

貌似得把web 相对路径转成绝对路径   
------其他解决方案--------------------
轻轻的问一句,你的这种需求能实现吗?如果是删除你自己网站下的文件应该只要有权限就没有问题,那样的话使用相对路径比较好,如果你想通过绝对路径删除别人网站中的内容那是不可能的,比如加入有个url http://www.baidu.com/download/1.rar,你通过这个url只能下载而不能删除的。
------其他解决方案--------------------
想要实现的是从客户端到服务器的上传下载删除操作,请问有什么好的建议么
------其他解决方案--------------------
楼上几位说的Server.MapPath()
需要引入System.Web.HttpContext.Current.Server.MapPath这个命名空间么
为什么添加了system.web.dll之后 
命名空间只能引入System.Web.HttpContext 再之后就找不到了