52,797
社区成员
发帖
与我相关
我的任务
分享
<!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>
<title>File UpLoad Test</title>
<script type="text/javascript" language="javascript">
function GetXmlHttpRequest()
{
var xmlHttp = null;
try
{
// Firefox, Opera 8.0+, Safari 非IE浏览器
xmlHttp = new XMLHttpRequest();
}
catch (e)
{
//IE浏览器
try
{
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
function UploadAndSubmit(url)
{
var xhr = GetXmlHttpRequest();
xhr.open("post", url, true);
xhr.onreadystatechange = function()
{
if (xhr.readyState == 4 && xhr.status == 200)
{
var t = document.getElementById("test");
t.innerHTML = xhr.responseText;
}
};
xhr.send(null);
}
function UploadCancel(f)
{
}
</script>
</head>
<body>
<center>
<h1>File UpLoad</h1>
<form id="FmUpLoad" name="FmUpLoad" method="post" enctype= "multipart/form-data" action="File.aspx">
<input type="file" id="f" name="f" />
<input type="button" id="BtnCancel" name="BtnCancel" value="取消" onclick="UploadCancel(f)" /><br />
<span id="SpUpedSize"></span>/<span id="SpTotalSize"></span>
<br />
<input type="submit" id="BtnUpLoad" value="UpLoad" />
</form>
<div id='test'></div>
</center>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace FileUpLoad.PageHandler
{
public partial class File : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//string header = Request.Headers.ToString();
/*
int count = Request.Files.Count;
Response.Write(count);
string url = Request.Url.ToString();
Response.Write(url);
*/
int cnt = Request.Files.Count;
for (int i = 0; i < cnt; i++)
{
HttpPostedFile file = Request.Files[i];
Response.Write(i+"<br>");
Response.Write(file.ContentLength + "<br>");
Response.Write(file.InputStream.Length + "<br>");
}
Response.Write(cnt);
}
}
}