加好友 发短信
天之飞雪
等级:青蜂侠
帖子:1427
积分:11370
威望:0
精华:7
注册:2007/12/25 16:21:28
|
Post By:2010/7/2 11:14:48 [只看该作者]
upload.aspx:
- if (this.IsPostBack)
- {
- UploadInfo uploadInfo = this.Session["UploadInfo"] as UploadInfo;
- if (uploadInfo == null)
- {
-
- const string js = "window.parent.onComplete('error', '无法上传文件。请刷新页面,然后再试一次);";
- ScriptManager.RegisterStartupScript(this, typeof(upload_aspx), "progress", js, true);
- }
- else
- {
-
- uploadInfo.IsReady = false;
-
-
- if (this.fileUpload.PostedFile != null && this.fileUpload.PostedFile.ContentLength > 0
-
- && this.fileUpload.PostedFile.ContentLength < 1048576)
- {
-
- string path = this.Server.MapPath(@"Uploads");
- string fileName = Path.GetFileName(this.fileUpload.PostedFile.FileName);
-
-
- uploadInfo.ContentLength = this.fileUpload.PostedFile.ContentLength;
- uploadInfo.FileName = fileName;
- uploadInfo.UploadedLength = 0;
-
-
- uploadInfo.IsReady = true;
-
-
- int bufferSize = 1;
- byte[] buffer = new byte[bufferSize];
-
-
- using (FileStream fs = new FileStream(Path.Combine(path, fileName), FileMode.Create))
- {
- while (uploadInfo.UploadedLength < uploadInfo.ContentLength)
- {
-
- int bytes = this.fileUpload.PostedFile.InputStream.Read(buffer, 0, bufferSize);
-
- fs.Write(buffer, 0, bytes);
-
- uploadInfo.UploadedLength += bytes;
-
-
- System.Threading.Thread.Sleep(100);
- }
- }
-
-
- File.Delete(Path.Combine(path, fileName));
-
-
- const string js = "window.parent.onComplete('success', '{0} 已成功上传');";
- ScriptManager.RegisterStartupScript(this, typeof(upload_aspx), "progress", string.Format(js, fileName), true);
- }
- else
- {
- if (this.fileUpload.PostedFile.ContentLength >= 1048576)
- {
- const string js = "window.parent.onComplete('error', '超出上传文件限制大小,请重新选择');";
- ScriptManager.RegisterStartupScript(this, typeof(upload_aspx), "progress", js, true);
- }
- else
- {
- const string js = "window.parent.onComplete('error', '上传文件出错');";
- ScriptManager.RegisterStartupScript(this, typeof(upload_aspx), "progress", js, true);
- }
- }
- uploadInfo.IsReady = false;
- }
- }
URL:http://www.aspxcs.net/HTML/2231191498.html
[此贴子已经被作者于2010-7-2 11:15:19编辑过]
|
|