您目前尚未登陆,请选择【登陆】或【注册
首页->上传下载->51aspx大文件上传并显示进度和上传速率示例及组建源码>>WebbUpload/WebbUpload.cs>>源码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:51aspx大文件上传并显示进度和上传速率示例及组建源码
当前文件:文件类型 LargeFileUpload/WebbUpload/WebbUpload.cs打开代码结构图
普通视图
		            
1using System; 2using System.IO; 3using System.Web; 4using System.Web.UI; 5using System.Web.UI.WebControls; 6 7namespace Webb.WAVE.Controls.Upload 8{ 9 //该源码下载自www.51aspx.com(51aspx.com) 10 11 /// <summary> 12 /// WebbUpload 的摘要说明。 13 /// </summary> 14 public class WebbUpload 15 { 16 string m_GUID; 17 string m_script; 18 public WebbUpload() 19 { 20 this.m_GUID = string.Empty; 21 Script m_script; 112 } 113 114 /// <summary> 115 /// Register progress bar to a button. 116 /// </summary> 117 /// <param name="uploadButton"></param> 118 /// <param name="causesValidation"></param> 119 public void RegisterProgressBar(Button uploadButton, bool causesValidation) 120 { 121 if (causesValidation) 122 { 123 uploadButton.CausesValidation = false; 124 uploadButton.Attributes["onclick"] = "if (typeof(Page_ClientValidate) == 'function') Page_ClientValidate();if(!Page_BlockSubmit){openProgress();}"; 125 } 126 else 127 { 128 uploadButton.Attributes["onclick"] = "openProgress();"; 129 } 130 UploadStatus uploadStatus = new UploadStatus(); 131 uploadStatus.Status = UploadStatus.UploadState.Uploading; 132 this.m_GUID = uploadStatus.UploadGUID; 133 HttpContext.Current.Application[("Upload_Status_"+this.m_GUID)] = uploadStatus; 134 string progressUrl = "progress.ashx?UploadGUID=" + this.m_GUID; 135 this.m_script = this.m_script.Replace("${url}$", progressUrl); 136 Page page = ((Page) WebbHelper.GetContext().Handler); 137 page.RegisterHiddenField("Webb_Upload_GUID", this.m_GUID); 138 page.RegisterStartupScript("ProgressScript", this.m_script); 139 page.Application.Add(("Webb_Upload_GUID"), this.m_GUID); 140 } 141 142 /// <summary> 143 /// 144 /// </summary> 145 /// <param name="uploadButton"></param> 146 /// <param name="causesValidation"></param> 147 public void RegisterProgressBar(LinkButton uploadButton, bool causesValidation) 148 { 149 if (causesValidation) 150 { 151 uploadButton.CausesValidation = false; 152 uploadButton.Attributes["onclick"] = "if (typeof(Page_ClientValidate) == 'function') Page_ClientValidate();if(!Page_BlockSubmit){openProgress();}"; 153 } 154 else 155 { 156 uploadButton.Attributes["onclick"] = "openProgress();"; 157 } 158 UploadStatus uploadStatus = new UploadStatus(); 159 uploadStatus.Status = UploadStatus.UploadState.Uploading; 160 this.m_GUID = uploadStatus.UploadGUID; 161 HttpContext.Current.Application[("Upload_Status_"+this.m_GUID)] = uploadStatus; 162 string progressUrl = "progress.ashx?UploadGUID=" + this.m_GUID; 163 this.m_script = this.m_script.Replace("${url}$", progressUrl); 164 Page page = ((Page) WebbHelper.GetContext().Handler); 165 page.RegisterHiddenField("Webb_Upload_GUID", this.m_GUID); 166 page.RegisterStartupScript("ProgressScript", this.m_script); 167 page.Application.Add(("Webb_Upload_GUID"), this.m_GUID); 168 } 169// public void RegisterProgressBar(LinkButton uploadButton) 170// { 171// RegisterProgressBar(uploadButton,false); 172// } 173 174 /// <summary> 175 /// Register progress bar to a button. 176 /// </summary> 177 /// <param name="uploadButton"></param> 178 /// <param name="causesValidation"></param> 179 public void RegisterProgressBar(WebControl m_controls) 180 { 181 //m_controls.Attributes["onclick"] = "if (typeof(Page_ClientValidate) == 'function') { if (Page_ClientValidate() == false) { return false; }} this.disabled = true;openProgress();__doPostBack('btn_upload','');if (typeof(Page_ClientValidate) == 'function') Page_ClientValidate();"; 182 m_controls.Attributes["onclick"] = "openProgress();"; 183 UploadStatus uploadStatus = new UploadStatus(); 184 uploadStatus.Status = UploadStatus.UploadState.Uploading; 185 this.m_GUID = uploadStatus.UploadGUID; 186 HttpContext.Current.Application[("Upload_Status_"+this.m_GUID)] = uploadStatus; 187 string progressUrl = "progress.ashx?UploadGUID=" + this.m_GUID; 188 this.m_script = this.m_script.Replace("${url}$", progressUrl); 189 Page page = ((Page) WebbHelper.GetContext().Handler); 190 page.RegisterHiddenField("Webb_Upload_GUID", this.m_GUID); 191 page.RegisterStartupScript("ProgressScript", this.m_script); 192 page.Application.Add(("Webb_Upload_GUID"), this.m_GUID); 193 } 194 195 public void EnableWebbUpload(bool i_enable) 196 { 197 Page page = ((Page) WebbHelper.GetContext().Handler); 198 page.RegisterHiddenField("Webb_Upload_Enable", i_enable.ToString()); 199 } 200 201 /// <summary> 202 /// Get a uploaded file. 203 /// </summary> 204 /// <param name="name"></param> 205 /// <returns></returns> 206 public UploadFile GetUploadFile(string name) 207 { 208 UploadFile uploadFile = new UploadFile(name); 209 return (uploadFile.FileName == string.Empty) ? null : uploadFile; 210 } 211 212 /// <summary> 213 /// 214 /// </summary> 215 /// <param name="m_path"></param> 216 public void SetTempPath(string m_path) 217 { 218 if(Directory.Exists(m_path)) 219 { 220 Page page = ((Page) WebbHelper.GetContext().Handler); 221 page.RegisterHiddenField("Webb_Upload_TempPath",m_path); 222 } 223 } 224 225 /// <summary> 226 /// Get all uploaded files. 227 /// </summary> 228 /// <param name="name"></param> 229 /// <returns></returns> 230 public UploadFileCollection GetUploadFileList(string name) 231 { 232 UploadFileCollection uploadFiles = new UploadFileCollection(); 233 string content = WebbHelper.GetContext().Request[name]; 234 if ((content == null) || (content == string.Empty)) 235 { 236 return uploadFiles; 237 } 238 else 239 { 240 string[] contentArray = content.Split(','); 241 for (int i = 0; i < contentArray.Length; i++) 242 { 243 string curContent = contentArray[i]; 244 if(IsEmptyFileContent(curContent)) uploadFiles.Add(new UploadFile(curContent)); 245 } 246 } 247 return uploadFiles; 248 } 249 private bool IsEmptyFileContent(string m_content) 250 { 251 string[] m_contents = m_content.Split(';'); 252 if(m_contents.Length<3)return true; 253 int m_start = m_contents[1].IndexOf("="); 254 if(m_start<0) return false; 255 string m_fileName = m_contents[1].Substring(m_start+1).Replace("\"",string.Empty); 256 if(m_fileName==string.Empty)return false; 257 return true; 258 } 259 } 260} 261
还没有找到您心仪的内容?请用.net源码大搜捕
代码片断 打包下载该项目完整源码:51aspx大文件上传并显示进度和上传速率示例及组建源码
51Aspx.com 版权所有 CopyRight © 2000-2008. 京ICP备06046876号