为了使自己以后不再去网上搜索,特记录下来

从uploadify官网http://www.uploadify.com/上下载文件

必要的文件:

1、jquery的js文件

2、jquery.uploadify.min.js

3、uploadify.css

4、uploadify.swf

页面的完整代码:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="scripts/jquery.min.js" type="text/javascript"></script>
<script src="scripts/uploadify/jquery.uploadify.min.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="scripts/uploadify/uploadify.css">
<style type="text/css">
body {
font: 13px Arial, Helvetica, Sans-serif;
}
.uploadify-button {
background-color: transparent;
border: none;
padding: 0;
}
.uploadify:hover .uploadify-button {
background-color: transparent;
}
</style>
</head> <body>
<h1>Uploadify在asp.net下使用Demo</h1>
<form>
<div id="queue"></div>
<input id="file_upload" name="file_upload" type="file" multiple="true">
</form> <script type="text/javascript">
$(function() {
$('#file_upload').uploadify({
'buttonText': '选择文件',
'buttonImage': 'scripts/uploadify/browse-btn.png', //按钮使用图片
//'buttonClass':'custom-class',
//'height':20,
//'width':20,
//'formData': { 'submitType': 'image', 'studentId': studentId, 'taskId': taskId },
'removeTimeout': 1, //进度条消失秒数
'fileTypeDesc': '图片文件',
'fileTypeExts': '*.jpg; *.jpeg; *.png; *.gif,*.bmp',
'onUploadSuccess': function (file, data, response) { //上传成功回调方法
data = eval("("+data+")");
if (data.error == 0) {
alert("上传成功" + data.filename);
} else {
alert(data.message);
return;
}
},
'swf' : 'scripts/uploadify/uploadify.swf',
'uploader': 'scripts/uploadify/UploadHandler.ashx'
});
});
</script>
</body>
</html>

  我的站点目录结构:

UploadHandler.ashx是处理上传的文件的一般处理程序:

public class UploadHandler : IHttpHandler
{
private HttpContext context; public void ProcessRequest(HttpContext context)
{
//文件保存路径
String savePath = context.Server.MapPath("~/UploadFiles/"); if (!Directory.Exists(savePath)) //如果这个路径不存在,则先创建
{
Directory.CreateDirectory(savePath);
} //定义允许上传的文件扩展名
Hashtable extTable = new Hashtable();
extTable.Add("image", "gif,jpg,jpeg,png,bmp"); //最大文件大小
int maxSize = 1000000;
this.context = context; HttpPostedFile file = context.Request.Files["Filedata"];
if (file == null)
{
showError("请选择文件。");
} if (file.InputStream == null || file.InputStream.Length > maxSize)
{
showError("上传文件大小超过限制。");
} String fileName = file.FileName; //文件名
String fileExt = Path.GetExtension(fileName).ToLower(); //扩展名 如 .jpg if (String.IsNullOrEmpty(fileExt) || Array.IndexOf(((String)extTable["image"]).Split(','), fileExt.Substring(1).ToLower()) == -1)
{
showError("上传文件扩展名是不允许的扩展名。\n只允许" + ((String)extTable["image"]) + "格式。");
} String newFileName = DateTime.Now.ToString("yyyyMMddHHmmss_ffff", DateTimeFormatInfo.InvariantInfo) + fileExt;
String filePath = savePath + newFileName; file.SaveAs(filePath); //将保存了的新的文件名返回给前端
Hashtable hash = new Hashtable();
hash["error"] = 0;
hash["filename"] = newFileName;
context.Response.AddHeader("Content-Type", "text/html; charset=UTF-8");
context.Response.Write(JsonConvert.SerializeObject(hash));
context.Response.End();
} private void showError(string message)
{
Hashtable hash = new Hashtable();
hash["error"] = 1;
hash["message"] = message;
context.Response.AddHeader("Content-Type", "text/html; charset=UTF-8");
context.Response.Write(JsonConvert.SerializeObject(hash));
context.Response.End();
} public bool IsReusable
{
get
{
return false;
}
}
}

  

源码下载(微云)

Uploadify在asp.net下使用Demo的更多相关文章

  1. 使用jQuery Uploadify在ASP.NET 上传附件

    Uploadify是JQuery的一个上传插件,实现的效果非常不错,带进度显示.Uploadify官方网址:http://www.uploadify.com/,在MVC中使用的方法可以参考 jQuer ...

  2. asp.net下调用Matlab生成动态链接库

    对于这次论文项目,最后在写一篇关于工程的博客,那就是在asp.net下调用matlab生成的dll动态链接库.至今关于matlab,c/c++(opencv),c#(asp.net)我总共写了4篇配置 ...

  3. jQuery Uploadify在ASP.NET MVC3中的使用

    1.Uploadify简介 Uploadify是基于jQuery的一种上传插件,支持多文件.带进度条显示上传,在项目开发中常被使用. Uploadify官方网址:http://www.uploadif ...

  4. QQ浏览器、搜狗浏览器等兼容模式下,Asp.NetCore下,Cookie、Session失效问题

    原文:QQ浏览器.搜狗浏览器等兼容模式下,Asp.NetCore下,Cookie.Session失效问题 这些狗日的浏览器在兼容模式下,保存Cookie会失败,是因为SameSiteMode默认为La ...

  5. ASP.NET下回车键的触发效果

    在ASP.NET下,在客户端触发回车键,默认调用了页面中第一个button,这有时是非常头痛的,比如页面的第一个按键是注销键时,想想也够可怕了. .net提供设置默认回车键的属性,this.Form. ...

  6. 转发 win7+iis7.5+asp.net下 CS0016: 未能写入输出文件“c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files 解决方案

    win7+iis7.5+asp.net下 CS0016: 未能写入输出文件“c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NE ...

  7. asp.net下的b/s架构

    最近一直在做asp.net下的b/s架构的程序.整理一下可以采用的架构. 简单三层架构 基于接口和工厂模式的三层 前台用jquery调用http请求(ashx),ashx再调用逻辑接口 虽然很早就知道 ...

  8. asp.net下cookie 的基础使用

    cookie作为在B/S开发中经常被使用到的东西,asp.net必然提供了现成的东西给我们使用. 就是这个对象:HttpCookie,当然了,对于asp.net来说,Request和Response中 ...

  9. ASP.NET下MVC设计模式的实现

    [转载]MVC架构在Asp.net中的应用和实现 转载自:http://www.cnblogs.com/baiye7223725/archive/2007/06/07/775390.aspx 摘要:本 ...

随机推荐

  1. javascript日期格式处理

    一. 服务端返回的日期和时间之间有T Asp.net MVC中 action返回前台的日期类型数据 是带有 T的,如: 2015-07-07T10:15:01. 这样的数据在Chrome浏览器,会自动 ...

  2. Flume-NG源码阅读之FileChannel

    FileChannel是flume一个非常重要的channel组件,非常常用.这个channel非常复杂,涉及的文件更多涉及三个包:org.apache.flume.channel.file.org. ...

  3. jmeter-请求参数化

    新建个scv文件,将我们需要传递的数据写进去(建议用notepad等编辑器,直接用excel转csv格式有可能会出现不能识别参数) 有多个参数用,分开 另存为 2.jmeter 新建请求,选择函数对话 ...

  4. scala学习手记14 - 单例对象

    java中的单例模式都很熟悉了:简单地说就是一个类只能有一个实例.在scala中创建单例对象非常简单,创建类时使用object关键字替换class即可.因为单例类无法初始化,所以不能向它的主构造函数传 ...

  5. Spring Boot的核心

    1.1.1.   入口类和@SpringBootApplication Spring Boot的项目一般都会有*Application的入口类,入口类中会有main方法,这是一个标准的Java应用程序 ...

  6. js中的BOM对象

    浏览器对象模型(BOM)以 window 对象为依托,表示浏览器窗口以及页面可见区域.同时, window对象还是 ECMAScript 中的 Global 对象,因而所有全局变量和函数都是它的属性, ...

  7. MySQL 入门篇

    历史 MySQL 是由 David Axmark.Allan Larsson 和 Michael Widenius 3 个瑞典人于 20 世纪 90 年代开发的一个关系型数据库.MySQL 之名取自创 ...

  8. Asp.net使用powershell管理hyper-v

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...

  9. kindeditor上传本地图片实例

    所需插件:kindeditor下载   密码: 5ry4 jsp文件: <script type="text/javascript" language="javas ...

  10. go 编译

    linux: set GOARCH=amd64 set GOOS=linux go build -o app_name main.go echo "编译完成,任意键退出" paus ...