asp.net save online pictures to the server instance _ practical tips

Source: Internet
Author: User

This article is based on a picture of the URL address, save the picture to the ASP.net server side of the implementation method.

Create the Getimage.aspx page with the following code:

<%@ Page language= "C #" autoeventwireup= true "codebehind=" GetImage.aspx.cs "inherits=" KeleyiTestWeb.KImage.GetImage "%> <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">  

The code for GetImage.aspx.cs is as follows:

/* Reference: http://keleyi.com/a/bjac/qwcsgskp.htm
* *
using System;
Using Keleyi.KFrame.KImage;

Namespace Keleyitestweb.kimage
{public
partial class GetImage:System.Web.UI.Page
{
protected void Page_Load (object sender, EventArgs e)
{

}

protected void Btnsave_click (object sender, EventArgs e)
{
String m_filename = DateTime.Now.ToFileTime (). ToString () + ". jpg";
String m_savename = "download/" + m_filename;
String m_savepath = Server.MapPath (m_savename);

if (Keleyiimgdownloader.downloadpicture (Tbpicurl.text, M_savepath,-1))
{
Ltltips.text = "Get Success";
Imgdownload.imageurl = M_savename;
}
else
Ltltips.text = "Get Failed";}}}


Here use the class Keleyiimgdownloader, set up in the Kframe project, code please download the project source (URL: https://kws.codeplex.com/SourceControl/changeset/ 610506BB3AB2B79EBF0D797C0F15939636FF76B3).

Run, enter the image URL, click the "Save" button, success, the effect of the chart is as follows:

View the source code of the page and see the src attribute of the picture:


The picture shown on the page is on the server where the program resides.

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.