您的位置:首页 > 其它

用.net改写的uploadify多文件上传控件

2014-05-20 09:05 232 查看
有图真相:



ASP.NET代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="UploadV2.aspx.cs" Inherits="TestUpload.UploadV2" %>

<!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-3.2.1/uploadify.css" rel="stylesheet" type="text/css" />
<script src="Scripts/jquery/jquery-1.8.1.min.js" type="text/javascript"></script>
<script src="Scripts/uploadify-3.2.1/jquery.uploadify.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$('#file_upload').uploadify({
'buttonText': '上传文件',
'width': 70,
'height': 20,
'swf': 'Scripts/uploadify-3.2.1/uploadify.swf',
'uploader': 'uploadhandler.ashx',
'onUploadSuccess' : function(file, data, response) {
alert(data);
},
'onUploadComplete': function (file) {
alert('The file ' + file.name + ' finished processing.');
}

});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:FileUpload ID="file_upload" runat="server" />
</div>
</form>
</body>
</html>


C#代码:

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

namespace TestUpload
{
/// <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 oldFileName = "";
string newFileName = "";
if (file != null)
{
oldFileName = file.FileName;//原文件名
newFileName = Guid.NewGuid().ToString();
int size = file.ContentLength;//附件大小

//context.Response.Write("{ Success = true, FileName = \"" + oldFileName + "\", SaveName = \"" + newFileName + "\" }");

}
else
{
//context.Response.Write("{ Success = false, Message = \"请选择要上传的文件!\" }");
}
context.Response.Write("上传的文件是:" + oldFileName);
//return Json(new { Success = true, FileName = fileName, SaveName = saveName });
}

public bool IsReusable
{
get
{
return false;
}
}
}
}


需要完整源码,请联系邮箱:wag.wag@163.com
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: