删除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");
}
}
[其他解释]