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

从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. Python类与标准库

    Python类 >>> class MyClass: ... """A simple example class""" . ...

  2. Java内存分析1 - 从两个程序说起

    这次看一些关于JVM内存分析的内容. 两个程序 程序一 首先来看两个程序,这里是程序一:JVMStackTest,看下代码: package com.zhyea.robin.jvm; public c ...

  3. R语言和中国地图

    上图是R语言绘制的按地域分布的数据图.更科学,更严谨,也更有质感的样子. 今天瞎写点东西,我在想数据分析的意义是什么,也许就是研究事物存在的形式.而事物存在的形式是什么样子呢,从最初的三维空间,爱因斯 ...

  4. 初始化spring容器的几种方法

    package ssh.spring; import java.io.IOException; import org.springframework.beans.factory.BeanFactory ...

  5. hdu4619

    题解: 最大独立集问题 显然对于每一对交叉的建边 然后求出最大独立集 最大独立集=n-最大匹配 代码: #include<cstdio> #include<cmath> #in ...

  6. vs中: 错误,未定义的标识符getline 的解决方法

    这种情况一般都是,在使用的时候没有include<string>而导致的,加上就可以正确编译通过

  7. 登录页面jsp跳转到另一个jsp 与jsp-Servlet-jsp

    登录页面jsp 到另一个jsp,与jsp-Servlet-jsp  都是可以从表单提交参数信息. 但是jsp-jsp ,只能通过<%=request.getParameter("use ...

  8. 【机器学习基石笔记】七、vc Dimension

    vc demension定义: breakPoint - 1 N > vc dimension, 任意的N个,就不能任意划分 N <= vc dimension,存在N个,可以任意划分 只 ...

  9. jQuery中this与$(this)的区别

    起初以为this和$(this)就是一模子刻出来.但是我在阅读时,和coding时发现,总不是一回事,这里就谈谈this与$(this)的区别. jQuery中this与$(this)的区别 $(&q ...

  10. 用函数式编程,从0开发3D引擎和编辑器(一)

    介绍 大家好,欢迎你踏上3D编程之旅- 本系列的素材来自我们的产品:Wonder-WebGL 3D引擎和编辑器 的整个开发过程,探讨了在从0开始构建3D引擎和编辑器的过程中,每一个重要的功能点.设计方 ...