⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 httpuploadhandler.cs

📁 上传的控件
💻 CS
字号:
#region License

/*
* SunriseUpload - Asp.net Upload Component
*
* Copyright (C) 2004 mic <mic4free@hotmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*
* In case your copy of SunriseUpload does not include a copy of the license, you may find it online at 
* http://www.gnu.org/copyleft/gpl.html
*
* You can find new release of this component at http://athena.9966.org/SunriseUpload .
*/

#endregion

using System;
using System.Text;
using System.Web;

namespace WUSGControl.Web.Upload
{
	/// <summary>
	/// 实现Http接口,处理进度条发送过来的请求
	/// </summary>
	public class HttpUploadHandler : IHttpHandler
	{
		/// <summary>
		/// Implement from IHttphanders
		/// </summary>
		public bool IsReusable
		{
			get { return true; }
		}

		/// <summary>
        /// 根据上传ID初始化当前上传文件的上传进度条.初始化进度条,
        /// 根据指定ID的上传状态返回格式化的XML状态信息到客户端
		/// </summary>
		/// <param name="uploadGUID"></param>
		public void InitProgress(string uploadGUID)
		{
			HttpContext context;
			UploadStatus uploadStatus = new UploadStatus(uploadGUID);
			
		}

		/// <summary>
		///根据状态类生成新的XML信息字符
		/// </summary>
		/// <param name="uploadStatus"></param>
		/// <param name="builder"></param>
		/// <param name="uploadGUID"></param>
		private void UpdateStatus(UploadStatus uploadStatus, StringBuilder builder, string uploadGUID)
		{
            //if (uploadStatus.State == UploadState.Uploading)
            //{
            //    builder.Replace("${FileName}$", uploadStatus.FileName);
            //    builder.Replace("${UploadProgress}$", uploadStatus.Percent.ToString());
            //    builder.Replace("${SurplusProgress}$", Convert.ToString(100 - uploadStatus.Percent));
            //    builder.Replace("${UploadSpeed}$", (Utils.GetFormatString(uploadStatus.Speed) + "/s"));
            //    builder.Replace("${LeftTime}$", Utils.GetFormatString(uploadStatus.LeftTime));
            //    builder.Replace("${BtnOK}$", "disabled");
            //    builder.Replace("${Refresh}$", ("<meta http-equiv=\"Refresh\" content=\"1\";URL=progress.ashx?UploadID=" + uploadGUID + "\">"));
            //}
            //else if (uploadStatus.State == UploadState.Completed)
            //{
            //    builder.Replace("${UploadProgress}$", uploadStatus.Percent.ToString());
            //    builder.Replace("${SurplusProgress}$", Convert.ToString(100 - uploadStatus.Percent));

            //    builder.Replace("${FileName}$", (uploadStatus.FileCount.ToString() + "个文件上传成功!"));
            //    builder.Replace("${UploadSpeed}$", (Utils.GetFormatString(uploadStatus.Speed) + "/s"));
            //    builder.Replace("${LeftTime}$", "已完成,无时间剩余");

            //    uploadStatus.Dispose();
            //    builder.Replace("${BtnOK}$", "onclick=\"javascript:window.opener=self;window.close();return false;\"");
            //    builder.Replace("${Refresh}$", "");
            //}
            //else
            //{
            //    builder.Replace("${FileName}$", "读取中...");
            //    builder.Replace("${UploadProgress}$", "0");
            //    builder.Replace("${SurplusProgress}$", "100");
            //    builder.Replace("${UploadSpeed}$", (Utils.GetFormatString(uploadStatus.Speed) + "/s"));
            //    builder.Replace("${LeftTime}$", "0 秒");
            //    builder.Replace("${BtnOK}$", "disabled");
            //    builder.Replace("${Refresh}$", ("<meta http-equiv=\"Refresh\" content=\"1\";URL=progress.ashx?UploadID=" + uploadGUID + "\">"));
            //}

            //if (uploadStatus.State == UploadState.Completed)
            //{
            //    builder.Replace("${BtnCancel}$", "onclick=\"javascript:window.opener=self;window.close();return false;\"");
            //}
            //else
            //{
            //    if(Utils.IsAccordantBrowser())
            //    {
            //        builder.Replace("${BtnCancel}$", "onclick=\"javascript:dialogArguments.location.href=dialogArguments.location.href;window.close();\"");					
            //    }
            //    else
            //    {
            //        builder.Replace("${BtnCancel}$", "onclick=\"javascript:window.opener.opener=null;window.opener.location.href=window.opener.location.href;window.close();this.disabled=true;\"");
            //    }
            //}

            //builder.Replace("${Script}$", "");

			//Utils.2writem("页面完整的HTML为 :" +  builder.ToString());
		}

		/// <summary>
		/// 实现入口
		/// </summary>
		/// <param name="context"></param>
		public void ProcessRequest(HttpContext context)
		{   
            //获得上传参数ID
			string uploadID = context.Request.QueryString["UploadID"];
			string filePath = context.Request.FilePath;
			//Utils.2writem("IhttpHandler的路径为" + filePath);
			filePath = filePath.Substring((filePath.LastIndexOf("/") + 1)).ToUpper();

			bool isUnknownRequest = false;
            //请求的文件必须是这个文件才可以进入这个处理流程,通过获得文件的上传状态,
            //生成一定格式的xml字符串,返回给客户端使用
			if (filePath == "PROGRESS.ASHX")
			{
				this.InitProgress(uploadID);
			}
			else
			{
				isUnknownRequest = true;
			}

			if (isUnknownRequest)
			{
				throw new HttpException(500, "unknown request");
			}
		}


	}


}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -