<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
<link href="http://www.appelsiini.net/stylesheets/main2.css" rel="stylesheet" type="text/css" />
<link rel="alternate" type="application/atom+xml" href="http://feeds.feedburner.com/tuupola" title="Atom feed" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script src="jquery.filestyle.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
$(function() {
$("input.file_1").filestyle({
image: "choose-file.gif",
imageheight : 22,
imagewidth : 82,
width : 100
});
$("input.file_1").bind('paste',function(e){
e.preventDefault();
});
$("input.file_1").keydown(function(event){
if(event.keyCode==8)
{
$("input.file_1").attr("value",'');
}
else
{
return false;
}
});
$("input.file_2").filestyle({
image: "choose-file.gif",
imageheight : 22,
imagewidth : 82,
width : 200
});
$("input.file_2").bind('paste',function(e){
e.preventDefault();
});
$("input.file_3").filestyle({
image: "choose-file.gif",
imageheight : 22,
imagewidth : 82,
width : 300
});
$("input.file_3").bind('paste',function(e){
e.preventDefault();
});
$("input.file_4").filestyle({
image: "choose-file.gif",
imageheight : 22,
imagewidth : 82,
width : 400
});
/*** $("input.file_4").bind('paste',function(e){
e.preventDefault();
});
**/
$("input.file_5").filestyle({
image: "choose-file.gif",
imageheight : 22,
imagewidth : 82,
width : 500
});
$("input.file_5").bind('paste',function(e){
e.preventDefault();
});
});
</script>
<style type="text/css">
.file_1 {
background: #fff;
color: #888;
}
.file_2 {
background: #eee;
color: #111;
}
.file_3 {
background: #eee;
color: #111;
}
.file_4 {
background: #eee;
color: #111;
}
.file_5 {
background: #fff;
color: #888;
}
#sidebar {
width: 0px;
}
#content {
width: 770px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<div id="wrap">
<div id="header">
<p>
<h1>File Style</h1><br />
<small>Style those darn file inputs. With jQuery of course.</small>
<ul id="nav">
<li id="first"><a href="/" class="active">weblog</a></li>
<li><a href="/projects" class="last">projects</a></li>
<!--
<li><a href="/cv" class="last">cv</a></li>
-->
</ul>
</p>
</div>
<div id="content">
<input id="File1" type="file" runat="server" class="file_1" /> <br />
<asp:Button ID="btnUpload" runat="server" Text="Upload All" οnclick="btnUpload_Click" />
<br />
<input type="file" class="file_2" /><br />
<input type="file" class="file_3" /><br />
<input type="file" class="file_4" /><br />
<input type="file" class="file_5" /><br />
</div>
</div>
</form>
</body>
</html>
==============
protected void btnUpload_Click(object sender, EventArgs e)
{
HttpFileCollection files=Request.Files;
for (int i = 0; i < files.Count; i++)
{
HttpPostedFile file=files[i];
if (file.ContentLength > 0)
{
file.SaveAs(Server.MapPath("MyFiles")+"//"+System.IO.Path.GetFileName(file.FileName));
}
}
}
===========
<script>
function fun()
{
alert("fdsa");
$.get("Handler.ashx", function(data){
alert("Data Loaded: " + data);
});
}
</script>
public class Handler : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
string str = "ss ";
HttpFileCollection hfc = context.Request.Files;
//
for (int i = 0; i < hfc.Count; i++)
{
HttpPostedFile hpf = hfc[i];
if (hpf.ContentLength > 0)
{
// hpf.SaveAs(context.Server.MapPath("MyFiles") + "//" +System.IO.Path.GetFileName(hpf.FileName));
hpf.SaveAs(context.Request.MapPath("MyFiles/") + hpf.FileName);
// context.Response.Write("<b>File: </b>" + hpf.FileName + " <b>Size:</b> " +
// hpf.ContentLength + " <b>Type:</b> " + hpf.ContentType + " Uploaded Successfully <br/>");
// str += hpf.FileName;
//+context.Request.Files[1].FileName
}
}
// context.Response.Write("Hello World"+str+" ==");
// HttpFileCollection files = context.Request.Files;
// System.Text.StringBuilder strMsg = new System.Text.StringBuilder();
// strMsg.Append("上传的文件分别是:<hr color=red>");
// string fileNN = "";
// for (int iFile = 0; iFile < files.Count; iFile++)
// {
///检查文件扩展名字
// HttpPostedFile postedFile = files[iFile];
// string fileName, fileExtension;
// fileName = System.IO.Path.GetFileName(postedFile.FileName);
// if (fileName != "")
// {
// fileNN += fileName + " ";
// fileExtension = System.IO.Path.GetExtension(fileName);
//strMsg.Append("上传的文件类型:" + postedFile.ContentType.ToString() + "<br>");
//strMsg.Append("客户端文件地址:" + postedFile.FileName + "<br>");
//strMsg.Append("上传文件的文件名:" + fileName + "<br>");
// strMsg.Append("上传文件的扩展名:" + fileExtension + "<br><hr>");
//'可根据扩展名字的不同保存到不同的文件夹
//注意:可能要修改你的文件夹的匿名写入权限。
// postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath("MyFiles/") + fileName);
//dfsaf.rar,1024,2,d:/桌面/fd.rar,rar|
// }
// }
// context.Response.Write("Hello World" + str + " =="+files[0].FileName);
}