删除URL路径下的文件,在线等 路径:"http://IP地址/文件夹名/文件" 在网上查了一些方法,但都会报错"URL格式不支持",谁来帮帮忙十分感谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 string allfile = "http://IP地址/文件夹名/文件";//存放文件 if (File.Exists(rarinfo)){ File.Delete(rarinfo); //删除} 这样试过了,File.Exists(rarinfo)找不到文件,永远是false 貌似得把web 相对路径转成绝对路径 转为相对路径,然后用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"); } } 轻轻的问一句,你的这种需求能实现吗?如果是删除你自己网站下的文件应该只要有权限就没有问题,那样的话使用相对路径比较好,如果你想通过绝对路径删除别人网站中的内容那是不可能的,比如加入有个url http://www.baidu.com/download/1.rar,你通过这个url只能下载而不能删除的。 楼上几位说的Server.MapPath()需要引入System.Web.HttpContext.Current.Server.MapPath这个命名空间么为什么添加了system.web.dll之后 命名空间只能引入System.Web.HttpContext 再之后就找不到了 如何在输出字符串时让其中某个字符带上下划线? Datagridview的动态录入到数据库 webBrowser.Document 不能取到的html的元素 怎么用Vs.net制作安装程序呢? 多级目录转换为json数据 熟悉vb和c#的请进,vb6转换成c#遇到问题,在线等,谢谢 一个字符串替换的问题. vs.net 2003 final beta 开发的程序 能在旧有的.net framework上运行么? 高手看过来,DataView的问题 求解:datagrid与dataset序号问题? 修改了系统时间后,项目会报错 interface类可以实现同名函数,但是参数和返回值不同的功能吗
if (File.Exists(rarinfo))
{
File.Delete(rarinfo); //删除
}
private string urlconvertorlocal(string imagesurl1)
{
//获取程序根目录
string tmpRootDir = Server.MapPath(System.Web.HttpContext.Current.Request.ApplicationPath.ToString());
//转换成服务器绝对路径
string imagesurl2 = tmpRootDir + imagesurl1.Replace(@"/", @"/");
return imagesurl2;
}
string strFilePath = aa.Replace("http://", "");
if (File.Exists(strFilePath))
{
File.Delete(strFilePath);
if (!File.Exists(strFilePath))
{
Response.Write("ok");
}
else
{
Response.Write("no");
} }
需要引入System.Web.HttpContext.Current.Server.MapPath这个命名空间么
为什么添加了system.web.dll之后
命名空间只能引入System.Web.HttpContext 再之后就找不到了