FCKeditor删除文件图片功能

PageValidate.cs文件代码

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

//inputData为上传内容
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);
                    }
           
            }

你可能感兴趣的:(fckeditor)