Uploadify jquery+falsh+UploadHandler.ashx
官方网:http://www.uploadify.com/ 只有PHP版本
对于我们.net的来说是一个遗憾!现在奉献一个c#版本,希望对大家有用。
看代码其实很简单,在做这个之前遇到许多问题,特别是在IHttpHandler 里面,只有经历过了才会体会到,还是给解决了!
直接运行html出现下面错误 要在vs运行下才没有下面错误
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | <! 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 > < meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> < title >Uploadify</ title > < link href="css/default.css" rel="stylesheet" type="text/css" /> < link href="css/uploadify.css" rel="stylesheet" type="text/css" /> < script type="text/javascript" src="scripts/jquery-1.3.2.min.js"></ script > < script type="text/javascript" src="scripts/swfobject.js"></ script > < script type="text/javascript" src="scripts/jquery.uploadify.v2.1.0.min.js"></ script > < script type="text/javascript"> $(document).ready(function() { $("#uploadify").uploadify({ 'uploader' : 'scripts/uploadify.swf', 'script' : 'scripts/UploadHandler.ashx', 'cancelImg' : 'scripts/cancel.png', 'folder' : 'uploads', 'queueID' : 'fileQueue', 'sizeLimit' : '5242880',//5M 'auto' : false, 'multi' : true , 'onError' : function (a, b, c, d) { if (d.status == 404) alert('Could not find upload script. Use a path relative to: '+'<?= getcwd() ?>'); else if (d.type === "HTTP") alert('error '+d.type+": "+d.status); else if (d.type ==="File Size") alert(c.name+' '+d.type+' Limit: '+Math.round(d.sizeLimit/1024)+'KB'); else alert('error '+d.type+": "+d.info); } }); }); </ script > </ head > < body > < div id="fileQueue"></ div > < input type="file" name="uploadify" id="uploadify" /> < p > < a href="javascript:$('#uploadify').uploadifyUpload()">Upload</ a >| < a href="javascript:$('#uploadify').uploadifyClearQueue()">Cancel All Uploads</ a > </ p > </ body > </ html > |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | <%@ WebHandler Language= "C#" Class= "UploadHandler" %> using System; using System.IO; using System.Net; using System.Web; public class UploadHandler : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain" ; context.Response.Charset = "utf-8" ; HttpPostedFile oFile = context.Request.Files[ "Filedata" ]; string strUploadPath = HttpContext.Current.Server.MapPath(@context.Request[ "folder" ])+ "\\" ; if (oFile != null ) { if (!Directory.Exists(strUploadPath)) { Directory.CreateDirectory(strUploadPath); } oFile.SaveAs(strUploadPath + oFile.FileName); context.Response.Write( "1" ); } else { context.Response.Write( "0" ); } } public bool IsReusable { get { return false ; } } } |
2011-3-18
其他版本:blueimp-jQuery-File-Upload c# 在54楼 下载 不同上面那个!!
点击Flash按钮无法打开链接的解决方案:
http://www.cnblogs.com/zengxiangzhan/archive/2009/09/12/1565349.html
分类:
文件上传
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!