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