您的位置:首页 > 其它

删除fckEditor编辑器中上传的图片

2008-01-03 18:13 405 查看
最近在做项目时做了这样一个功能,已减少垃圾图片!

PageValidate.cs文件代码

private static Regex RegEditImg = new Regex(@"img[^>]*src/s*=/s*[""|']?(?<url>[^""']*)[""|']?[^<>]*>",RegexOptions.IgnoreCase);

public static List<string> ImgUrl(string inputData)
{
MatchCollection matchs = RegEditImg.Matches(inputData);
List<string> Img=new List<string>();
foreach (Match m in matchs)
{
Img.Add(m.Groups[1].Value);
}
return Img;
}

在做修改操作时候

List<string> ImgUrl = PageValidate.ImgUrl(NewsModel1.NewsContent);
for (int i = 0; i < ImgUrl.Count; i++)
{
string TempImgUrl = Server.MapPath(ImgUrl[i].ToString());

//修改后数据是否存在原有图片
List<string> ModifyImgUrl = PageValidate.ImgUrl(NewsModel.NewsContent);

if (!ModifyImgUrl.Contains(ImgUrl[i]) && File.Exists(TempImgUrl))
{
File.Delete(TempImgUrl);
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: