const string _RegSubFix = @"/.[/w]+$"; const string _RegZip = @"/.zip|/.rar"; protected void btnUpload_Click(object sender, EventArgs e) { if (filUpload.HasFile) { string subfix = Regex.Match(filUpload.FileName, _RegSubFix).Value.ToLower(); if (filUpload.PostedFile.ContentType == "application/octet-stream" && !Regex.IsMatch(filUpload.FileName, _RegZip)) { WebManageShell.WebHelp.Alert(this.Page, "不受支持的文件格式。"); return; } string folder = ConfigurationManager.AppSettings["UploadPath"] + "//" + DateTime.Now.ToString("yyyyMM"); try { if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } string file = folder + "//" + DateTime.Now.ToFileTimeUtc().ToString() + subfix; filUpload.SaveAs(file); WebManageShell.WebHelp.Alert(this.Page,"文件上传成功。"); } catch { WebManageShell.WebHelp.Alert(this.Page, "文件上传失败。"); } } else { WebManageShell.WebHelp.Alert(this.Page, "你没有上传文件。"); } }