62,040
社区成员
发帖
与我相关
我的任务
分享
public int Check_ContentImg(string post_id)
{
//同样如果要查询发的帖子里是否有音乐,媒体文件等只要在like中指定关键字
strsql = "select count(*) from Bbs_Post where Post_Content like '%.jpg%' or Post_Content like '%.gif' and Post_Id=" + post_id;
return ExecuteScalar(strsql);
}
public void Del_BbsPost(string postid)
{
if (bbs_post.Check_ContentImg(postid) > 0) //说明内容是有图片的
{
System.IO.File.Delete(文件路径)//删除文件夹中图片, 不知道如何得到路径 }
if (bbs_post.Del_BbsPost(postid)) //删除帖子方法
{
Jscript.Alert("删除帖子成功")
}
}
string str = @"<img width=100 src=""files.jpg""> This is a test page <img width=100 src=""files2.jpg""> hello world, html test <img width=100 src=""ffword.jpg""> from here, wodd. <span></span>
This is a test page <img width=100 src=""files2.jpg""> hello world, html test <img width=100 src=""ffword.jpg""> from here, wodd. <span></span>";
Regex reg = new Regex(@"(?is)<img[^>]*?src=(['""\s])?(?<src>[^'""\s]*?)\1[^>*]?>");
MatchCollection match = reg.Matches(str);
foreach (Match m in match)
{
Response.Write(m.Groups["src"].Value);
}
//删除的时候先根据id获取留言内容,在用正择匹配出图片路径
//然后在File.Delete(路径);
//最后在把留言内容删了
using System.Text.RegularExpressions;
private static Regex RegEditImg = new Regex(@"img[^>]*src\s*=\s*[""|']?(?<url>[^""']*)[""|']?[^<>]*>", RegexOptions.IgnoreCase);
public static ArrayList ImgUrl(string inputData)
{
MatchCollection matchs = RegEditImg.Matches(inputData);
ArrayList Img = new ArrayList();
foreach(Match m in matchs)
{
Img.Add(m.Groups[1].Value);
}
return Img;
}
......根据文章ID查询文章内容代码省略.
sqlRead.Read();
ArrayList arrayList = ImgUrl(sqlRead["Article"].ToString()); //调用上面的正则的方法,将获取的图片地址放到一个ArrayList中
for (int i = 0; i < arrayList.Count; i++)
{
string temPath = Server.MapPath(arrayList[i].ToString());
if (File.Exists(temPath))
{
File.Delete(temPath);
}
}
using System.Text.RegularExpressions;
private static Regex RegEditImg = new Regex(@"img[^>]*src\s*=\s*[""|']?(?<url>[^""']*)[""|']?[^<>]*>", RegexOptions.IgnoreCase);
public static ArrayList ImgUrl(string inputData)
{
MatchCollection matchs = RegEditImg.Matches(inputData);
ArrayList Img = new ArrayList();
foreach(Match m in matchs)
{
Img.Add(m.Groups[1].Value);
}
return Img;
}
ArrayList arrayList = ManageNews.ImgUrl(sqlRead["Article"].ToString()); //将获取的图片地址放到一个ArrayList中
for (int i = 0; i < arrayList.Count; i++)
{
string temPath = Server.MapPath(arrayList[i].ToString());
if (File.Exists(temPath))
{
File.Delete(temPath);
}
}