Download the image to the server C # code based on the URL,

Source: Internet
Author: User

Download the image to the server C # code based on the URL,

Download the image to the server C # code based on the URL

 

ASPX page code:

<% @ Page Language = "C #" AutoEventWireup = "true" CodeBehind = "GetPictureByUrl. aspx. cs" Inherits = "HoverTreeMobile. GetPictureByUrl" %> <! DOCTYPE html> 

 

Riddle:

Go down with tears (guess a country name)

Http://m.hovertree.com/miyu/bjae/4gwevb53.htm

 

Cs Page code:

Using System; namespace HoverTreeMobile {public partial class GetPictureByUrl: System. web. UI. page {protected void Page_Load (object sender, EventArgs e) {} protected void btnImg_Click (object sender, EventArgs e) {try {System. net. webClient m_hvtWebClient = new System. net. webClient (); // if the image format is not specified // for Example http://hovertree.com/hvtart/bjae/t2lo8pf7.htm It is an htm file, not an image if (! (TextBoxImgUrl. text. endsWith (". jpg ") | textBoxImgUrl. text. endsWith (". gif ") | textBoxImgUrl. text. endsWith (". png ") {ltlTips. text = "the URL of the input image is not in the specified format"; return;} // generate a random image file name string m_picFileName = HoverTree. hoverTreeFrame. utils. getHoverTreeString () + HoverTree. hoverTreeFrame. hoverString. getLastStr (textBoxImgUrl. text, 4); string m_keleyiPicture = Server. mapPath ("/hovertreeimages/" + m_picFileName); // download the m_hvtWebClient.DownloadFile (textBoxImgUrl. text, m_keleyiPicture); hvtImg. imageUrl = "/hovertreeimages/" + m_picFileName; ltlTips. text = string. empty;} catch (Exception ex) {ltlTips. text = ex. toString ();}}}}

 

 

// Generate a random image file name string m_picFileName = HoverTree. HoverTreeFrame. Utils. GetHoverTreeString () + HoverTree. HoverTreeFrame. HoverString. GetLastStr (textBoxImgUrl. Text, 4 );
For the above Code, download the source code to view the detailed implementation method. Partial to http://hovertree.com/hvtart/bjae/tlhx2yn2.htm

 

HoverTree open-source project

Added the function of downloading images to the server based on the website.

See the HoverTreeMobile Project

Http://hovertree.com

Why?

Source code download http://files.cnblogs.com/files/jihua/hovertreeCode.rar

 

Http://www.cnblogs.com/jihua/p/webfront.html

Related Article

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.