Asp.net + jquery. form asynchronous Image Upload method (attached to jquery. form. js download ),

Source: Internet
Author: User

Asp.net + jquery. form asynchronous Image Upload method (attached to jquery. form. js download ),

This document describes how to use asp.net + jquery. form to upload images asynchronously. We will share this with you for your reference. The details are as follows:

First, we need to prepare:

Click here to download jquery.

Click here to download jquery. form. js.

Page JqueryFormTest. aspx:

<% @ Page Language = "C #" AutoEventWireup = "true" CodeFile = "JqueryFormTest. aspx. cs" Inherits = "JqueryFormTest" %> <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

Img. ashx:

<% @ WebHandler Language = "C #" Class = "img" %> using System; using System. web; public class img: IHttpHandler {public void ProcessRequest (HttpContext context) {context. response. contentType = "text/plain"; // get the object of the uploaded file HttpPostedFile img = context. request. files ["btnfile"]; // get the name of the uploaded file string s = img. fileName; // obtain the name of the uploaded file. (the absolute path is also associated during ie upload. Only the file name is obtained here.) string str = s. substring (s. lastIndexOf ("\") + 1); s Tring path = "~ /Upload/"+ str; // Save the img file. saveAs (context. server. mapPath (path); // HttpRuntime. appDomainAppVirtualPath is used to obtain the virtual path name of the application. Because the image context cannot be displayed because it is not automatically added when the response is sent to the page. response. write (HttpRuntime. appDomainAppVirtualPath + path. substring (1); // path. substring (1) is used to remove the first ~ Character} public bool IsReusable {get {return false ;}}}

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.