Public static string dowimg (string content1, string key)
{
String content = content1;
Matchcollection M = getregduo (" ", Content );
Foreach (match item in m)
{//
String imgurl = getreg ("src = \" (. + ?) \ "", Item. Value); // original image URL
If (imgurl. indexof ("lkjfds ")! =-1)
{
String DDD = "DDD ";
}
String houzui = imgurl. substring (imgurl. lastindexof ("."); // image suffix
String imgname = guid. newguid (). tostring () + houzui;
String name = "http://www.lkjfds.com/taoimg/" + key + "/" + imgname; // the path of the modified image;
Try
{
Dal. database. execproc ("insert into IMG (URL, houurl) values ('" + imgurl + "', '" + name + "')"); // put existing links into the database
Content = content. Replace (imgurl, name );
}
Catch (exception E)
{
If (E. tostring (). indexof ("Index ")! =-1) // indicates that the image already exists in the database.
{
Name = Dal. database. returnscalar ("select houurl from IMG where url = '" + imgurl + "'"). tostring ();
Content = content. Replace (imgurl, name );
Continue;
}
Throw;
}
// Download the image if not
Stream Ss = httpweb. getget (imgurl, new system. net. cookiecontainer (); // download the image
Image IMG = image. fromstream (SS );
IMG. Save (environment. currentdirectory + "/" + key + "/" + imgname); // Save the image
}
Return content;
}