. Net downloads images, downloads duplicate images, saves databases, and saves images.

Source: Internet
Author: User

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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.