onAfterRender: function(){
upload_url: "/File/Upload",
file_size_limit: "10 MB",
file_types:"*.jpg;*.png;*.gif;*.bmp;",
file_types_description: "图片文件",
file_post_name: "Filedata",
swfupload_preload_handler: me.UploadPreLoad,
swfupload_load_failed_handler: me.UploadLoadFailed,
swfupload_loaded_handler: me.UploadLoaded,
file_queued_handler: me.fileQueued,
file_queue_error_handler: me.fileQueueError,
file_dialog_complete_handler: me.fileDialogComplete,
upload_start_handler: me.uploadStart,
upload_progress_handler: me.uploadProgress,
upload_error_handler: me.uploadError,
upload_success_handler: me.uploadSuccess,
upload_complete_handler: me.uploadComplete,
queue_complete_handler: me.queueComplete,
button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
button_placeholder_id: me.spanid,
button_text_top_padding: 0,
button_text_left_padding: 0,
flash_url: "Scripts/swfupload/swfupload.swf", // Relative tothis file
flash9_url: "Scripts/swfupload/swfupload_FP9.swf", // Relativeto this file
custom_settings: { scope: me },
UploadPreLoad:function(){
UploadLoadFailed:function(){
fileQueueError:function(file,errorCode, message){
if(errorCode === SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED) {
dlg("选择的文件太多。\n一次最多上传100个文件,而你选择了" +message + "个文件。");
caseSWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
this.debug("错误代码: File too big, File name: " +file.name + ", File size: " + file.size + ", Message: " +message);
caseSWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
this.debug("ErrorCode: Zero byte file, File name: " + file.name + ", File size: "+ file.size + ", Message: " + message);
caseSWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
this.debug("ErrorCode: Invalid File Type, File name: " + file.name + ", File size:" + file.size + ", Message: " + message);
this.debug("ErrorCode: " + errorCode + ", File name: " + file.name + ", Filesize: " + file.size + ", Message: " + message);
fileDialogComplete:function(numFilesSelected,numFilesQueued){
varme=this.customSettings.scope,sels=me.tree.getSelectionModel().getSelection(),path="/";
SimpleCMS.postParams.path=path;
this.setPostParams(SimpleCMS.postParams);
Ext.Msg.alert("请先选择文件夹。");
uploadStart:function(file){
varme=this.customSettings.scope;
me.progress.updateProgress(0);
me.progress.updateText("正在上传文件"+file.name+"...");
uploadProgress:function(file,bytesLoaded, bytesTotal){
varpercent = bytesLoaded / bytesTotal;
varme=this.customSettings.scope;
me.progress.updateProgress(percent);
me.progress.updateText("正在上传文件"+file.name+"...");
uploadError:function(file,errorCode, message){
varme=this.customSettings.scope;
me.progress.updateText("正在上传文件"+file.name+"...");
caseSWFUpload.UPLOAD_ERROR.HTTP_ERROR:
me.progress.updateText("上传错误:" + message);
this.debug("ErrorCode: HTTP Error, File name: " + file.name + ", Message: " +message);
caseSWFUpload.UPLOAD_ERROR.UPLOAD_FAILED:
me.progress.updateText("上传失败。");
this.debug("ErrorCode: Upload Failed, File name: " + file.name + ", File size: "+ file.size + ", Message: " + message);
caseSWFUpload.UPLOAD_ERROR.IO_ERROR:
me.progress.updateText("Server(IO) 错误");
this.debug("ErrorCode: IO Error, File name: " + file.name + ", Message: " +message);
caseSWFUpload.UPLOAD_ERROR.SECURITY_ERROR:
me.progress.updateText("安全错误");
this.debug("ErrorCode: Security Error, File name: " + file.name + ", Message: " +message);
caseSWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED:
me.progress.updateText("文件大小超出限制。");
this.debug("ErrorCode: Upload Limit Exceeded, File name: " + file.name + ", File size:" + file.size + ", Message: " + message);
caseSWFUpload.UPLOAD_ERROR.FILE_VALIDATION_FAILED:
me.progress.updateText("验证失败。");
this.debug("ErrorCode: File Validation Failed, File name: " + file.name + ", Filesize: " + file.size + ", Message: " + message);
caseSWFUpload.UPLOAD_ERROR.FILE_CANCELLED:
caseSWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED:
me.progress.updateText("停止");
me.progress.updateText("未知错误:" + errorCode);
this.debug("ErrorCode: " + errorCode + ", File name: " + file.name + ", Filesize: " + file.size + ", Message: " + message);
uploadSuccess:function(file,serverData){
varme=this.customSettings.scope;
me.progress.updateProgress(1);
me.progress.updateText(serverData);
uploadComplete:function(file){
if(this.getStats().files_queued > 0) {
varme=this.customSettings.scope;
me.progress.updateProgress(1);
me.progress.updateText("所有文件已上传。");
queueComplete:function(numFilesUploaded){
varme=this.customSettings.scope;
me.progress.updateProgress(1);
me.progress.updateText("已上传"+ numFilesUploaded + "个文件");
protected void Application_BeginRequest()
varRequest = HttpContext.Current.Request;
varResponse = HttpContext.Current.Response;
string session_param_name = "ASPSESSID";
string session_cookie_name = "ASP.NET_SESSIONID";
if(HttpContext.Current.Request.Form[session_param_name] != null)
UpdateCookie(session_cookie_name,HttpContext.Current.Request.Form[session_param_name]);
elseif (HttpContext.Current.Request.QueryString[session_param_name] != null)
UpdateCookie(session_cookie_name,HttpContext.Current.Request.QueryString[session_param_name]);
string auth_param_name = "AUTHID";
string auth_cookie_name = FormsAuthentication.FormsCookieName;
if(HttpContext.Current.Request.Form[auth_param_name] != null)
UpdateCookie(auth_cookie_name,HttpContext.Current.Request.Form[auth_param_name]);
elseif (HttpContext.Current.Request.QueryString[auth_param_name] != null)
UpdateCookie(auth_cookie_name,HttpContext.Current.Request.QueryString[auth_param_name]);
Response.StatusCode = 500;
Response.Write("Error Initializing Session");
private static void UpdateCookie(stringcookie_name, string cookie_value)
HttpCookie cookie =HttpContext.Current.Request.Cookies.Get(cookie_name);
cookie = new HttpCookie(cookie_name);
//SWFUpload 的Demo中给的代码有问题,需要加上cookie.Expires 设置才可以
cookie.Expires = DateTime.Now.AddYears(1);
HttpContext.Current.Request.Cookies.Add(cookie);
cookie.Value = cookie_value;
HttpContext.Current.Request.Cookies.Set(cookie);
[AjaxAuthorize(Roles = "普通用户,系统管理员")]
stringpath = Request["path"] ?? "";
string[]filetypes = { "jpg", "gif", "png","bmp" };
stringdir = Server.MapPath(root + path);
if(Directory.Exists(dir))
HttpPostedFileBase file = Request.Files["Filedata"];
string filename = file.FileName.ToLower();
string extname = filename.Substring(filename.LastIndexOf(".")+ 1, 3);
if(file.ContentLength <= 0)
elseif (file.ContentLength > 10485760)
elseif (!filetypes.Contains(extname))
return "文件类型错误。" + extname;
file.SaveAs(dir + "\\" + filename);
return "文件已上传。" + dir + "\\" + newfilename;