在asp.net中使用jquery.uploadify-3.1实现上传
来源:互联网 发布:最优化教学 编辑:程序博客网 时间:2024/05/16 16:56
using System;
jquery.uploadify-3.1是基于jquery的一款文件上传插件
插件下载地址:http://www.uploadify.com/wp-content/uploads/files/uploadify-v3.1.zip
文档地址:http://www.uploadify.com/documentation/
第一步:
创建一个asp.net网站或者web应用程序,并添加红框内的文件,其中uploadify-v3.1是下载的插件解压后直接拷贝到Script目录下的.
第二步:
创建一个httpHandler处理文件
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.IO;namespace WebApplication1.Handlers{/// <summary>/// UploadHandler 的摘要说明/// </summary>public class UploadHandler : IHttpHandler{public void ProcessRequest(HttpContext context){context.Response.ContentType = "text/plain";context.Response.Charset = "utf-8";HttpPostedFile file = context.Request.Files["Filedata"];string uploadPath =HttpContext.Current.Server.MapPath(@context.Request["folder"]) + "\\";if (file != null){if (!Directory.Exists(uploadPath)){Directory.CreateDirectory(uploadPath);}file.SaveAs(uploadPath + file.FileName);//下面这句代码缺少的话,上传成功后上传队列的显示不会自动消失context.Response.Write("1");}else{context.Response.Write("0");}}public bool IsReusable{get{return false;}}}}
第三步:
编写html代码
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="UploadTest.aspx.cs" Inherits="WebApplication1.UploadTest" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title></title> <link href="/Scripts/uploadify-v3.1/uploadify.css" rel="stylesheet" type="text/css" /> <script src="/Scripts/jquery-1.4.1.js" type="text/javascript"></script> <script type="text/javascript" src="/Scripts/uploadify-v3.1/jquery.uploadify-3.1.min.js"></script> <script type="text/javascript"> $(function () { $('#upload').uploadify({ 'formData': { 'folder': '/Uploads' }, 'buttonText': '选择文件', 'buttonClass': 'browser', 'removeCompleted': false, 'swf': '/Scripts/uploadify-v3.1/uploadify.swf', 'debug': false, 'height': 15, 'width':70, 'uploader': '/Handlers/UploadHandler.ashx' }); }); </script> <style type="text/css"> .browser { color: White; } </style></head><body> <form id="form1" runat="server"> <div> <input type="file" name="upload" id="upload" /> </div> </form></body></html>
第四步:完成查看效果
有人可能遇到以下问题:
?:上传大文件的IO Error问题:
解决办法:修改web.config
<system.web> <httpRuntime maxRequestLength="3097151" executionTimeout="50000"/> </system.web>
?:500错误,可能是你的handler文件错误
为懒人附上源码吧(O(∩_∩)O~):
http://dl.dbank.com/c0g2mem8ho
- 在asp.net中使用jquery.uploadify-3.1实现上传
- 关于 jquery Uploadify 上传插件 在 asp.net中 的使用
- JQuery多文件上传插件Uploadify在ASP.NET中的实现
- jquery uploadify 上传控件ASP.NET使用总结
- ASP.NET MVC 4 中Jquery上传插件Uploadify简单使用-版本:3.2.1
- JQuery上传插件Uploadify使用详解.net中使用
- jQuery Uploadify在ASP.NET MVC3中的使用
- jQuery Uploadify在ASP.NET MVC3中的使用
- jQuery Uploadify在ASP.NET MVC3中的使用
- asp.net+uploadify实现图片上传图片
- 在ASP.NET中使用JQuery多文件上传插件
- asp.net中使用Uploadify插件实现多张图片上传,上传后可显示缩略图、删除图片
- ASP.NET MVC使用Uploadify上传文件
- 使用uploadify组件在struts2中实现上传
- JQuery.uploadify 上传文件插件的使用详解 for ASP.NET
- C#,ASP.NET jquery uploadify上传控件中文乱码解决办法
- ASP.NET jquery.uploadify上传控件中文乱码解决办法
- asp.net 中uploadify上传图片在火狐中报 http error (302)错误解决方案
- 初创型团队容易在用户体验方面犯的十个错误
- 真想说再见,隐身帝们
- struts2图片上传,生成缩印,水印等
- error中成长001:Myeclipse连接mysql的时候出现错误
- AspNetPager分页控件
- 在asp.net中使用jquery.uploadify-3.1实现上传
- 构建细节,组织有顺序关系的语句,改善软件质量,改善源代码质量
- IT行业的各岗位职责
- 优化UITableView性能
- Linux的双链表list_head
- 5分钟搞定内存字节对齐
- 我们都一样
- App Store生存:iOS开发者经验分享
- 为Django Admin后台写对应页面的方法