<script src="../scripts/xmlLib.js"></script>
<script>
var r = "传输: {0}K 还未完成";
var s = "您的文件已经上传完成";
var t = "上传失败";
function progressBar()
{
this.totalSize = 100;
this.sizeCompleted = 0;
this.percentDone = "0%";
this.setSize = function(totalSize, size)
{
var oProgressInfo = document.getElementById("progressInfo");
var oProgress = document.getElementById("progress");
if (oProgress == null || oProgressInfo == null)
return;
if (totalSize <= 0)
return;
this.totalSize = totalSize;
this.sizeCompleted = size;
if (size < 0)
this.sizeCompleted = 0;
else if (size > this.totalSize)
this.sizeCompleted = this.totalSize;
var sizeLeft = 0;
var progressInfoText = "";
sizeLeft = this.totalSize - this.sizeCompleted;
this.percentDone = Math.round(size / this.totalSize * 100) + "%";
oProgress.style.width = this.percentDone;
if (sizeLeft > 0)
progressInfoText = r.replace("{0}", sizeLeft);
else
progressInfoText = s;
oProgressInfo.innerHTML = progressInfoText;
}
this.UploadError = function()
{
var oProgressInfo = document.getElementById("progressInfo");
var oProgress = document.getElementById("progress");
if (oProgressInfo != null)
oProgressInfo.innerHTML = t;
if (oProgress != null)
oProgress.style.width = "0";
}
this.UploadComplete = function()
{
var oProgressInfo = document.getElementById("progressInfo");
var oProgress = document.getElementById("progress");
if (oProgressInfo != null)
oProgressInfo.innerHTML = s;
if (oProgress != null)
oProgress.style.width = "100%";
}
}
var iTimerID = null;
var xmlHttp = XmlHttpPool.pick();
var url = "progress.aspx?UploadID=<%=Request.QueryString["UploadID"]%>"
var pb = new progressBar();
function LoadProgressInfo()
{
if(document.all.uploadFile.value!="")
{
document.all.tdbar.style.display = '';
}
try
{
xmlHttp.open("GET", url + "&t=" + Math.random(), true);
xmlHttp.send(null);
xmlHttp.onreadystatechange = function()
{
LoadData(xmlHttp);
}
}
catch(e)
{
alert(e)
}
}
function LoadData(xmlhttp)
{
if (xmlhttp.readyState == 4)
{
iTimerID = window.setTimeout("LoadProgressInfo()", 500);
try{
eval(xmlhttp.responseText);
}
catch(e)
{
alert(e)
}
}
}
function ClearTimer()
{
if (iTimerID != null)
{
window.clearTimeout(iTimerID);
iTimerID = null;
}
}
function UploadCancel()
{
location.href = location.href;
}
function validate()
{
if(document.all.uploadFile.value=="")
{
alert("请选择文件路径");
return false;
}
if(document.all.uploadFile.value.indexOf(".") == -1)
{
alert("请选择正确文件路径");
return false;
}
return true;
}
</script>
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using LogicLayer;
using LogicLayer.Upload;
namespace edzh
{
/// <summary>
/// 上传进度反映页面
/// </summary>
public class Progress : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
string uploadId = Request.QueryString["UploadID"];
string scriptText = "";
string scriptUploading = "pb.setSize({0}, {1});";
string scriptClearTimer = "ClearTimer();";
string scriptUploadComplete = "pb.UploadComplete();" + scriptClearTimer;
string scriptUploadError = "pb.UploadError();";
string length = "";
string read = "";
LogicLayer.Upload.Progress progress = LogicLayer.Upload.HttpUploadModule.GetProgress(uploadId, Application);
if (progress != null)
{
// 如果正在接收数据,利用脚本来通知前端进度条
//
if (progress.State == UploadState.ReceivingData)
{
length = (progress.ContentLength / 1024).ToString();
read = (progress.BytesRead / 1024).ToString();
scriptText = string.Format(scriptUploading, length, read);
}
else if(progress.State == UploadState.Complete)
{
scriptText = scriptUploadComplete;
}
else
{
scriptText = scriptUploadError;
}
}
else
{
//scriptText = scriptUploadError;
}
Response.Clear();
Response.Write(scriptText);
Response.End();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}




博客
资料
短消息
搜索
加为好友
成为Fans
江苏


