public void DataFilseAdd(HttpContext context) { SessionUserModel currentUser = context.Session["UserInfo"] as SessionUserModel; string pt = context.Request["Filename"].ToString(); HttpPostedFile postedFile = context.Request.Files["Filedata"]; //获取上传信息对象 string filename = postedFile.FileName; //获取上传的文件 名字 string tempPath = UploadFileCommon.CreateDir("File"); //获取保存文件夹路径。 string savepath = context.Server.MapPath(tempPath); //获取保存路径 string sExtension = filename.Substring(filename.LastIndexOf('.')); //获取拓展名 int fileLength = postedFile.ContentLength; //获取文件大小 string fileContentLength = fileSizs(postedFile.ContentLength); //转换成MB,GB,TB if (!Directory.Exists(savepath)) //查看当前文件夹是否存在 { Directory.CreateDirectory(savepath); } //string sNewFileName =DESEncrypt.Encrypt(DateTime.Now.ToString("yyyyMMddhhmmsfff"));//上传后的文件名字 string sNewFileName = Guid.NewGuid().ToString(); string OperationID = context.Request.QueryString["OperationID"]; //业务ID string SessionID = context.Request.QueryString["SessionID"]; //SessionID string FileType = context.Request.QueryString["FileType"]; //附件的类型 if (!string.IsNullOrEmpty(FileType)) { FileType = "未归类"; } //if (!filename.Contains("-")) //{ // FileType = context.Request.QueryString["FileType"];//附件的类型 // if (!string.IsNullOrEmpty(FileType)) // { // FileType = HttpUtility.UrlDecode(FileType); // } //} //else //{ // string[] fname = filename.Split('-'); // if (fname.Count() > 0) // { // FileType = fname[0]; // } // else // { // FileType = context.Request.QueryString["FileType"];//附件的类型 // if (!string.IsNullOrEmpty(FileType)) // { // FileType = HttpUtility.UrlDecode(FileType); // } // } //} //string types = context.Request.QueryString["FileType2"];//当前选中的类别节点 //if (!string.IsNullOrEmpty(types)) //{ // types = HttpUtility.UrlDecode(types); //} if (OperationID != "" && SessionID != "" && OperationID != null) { List <Sys_ModelFile> ModelFilelist = null; if (context.Session[SessionID] == null) { ModelFilelist = new List <Sys_ModelFile>(); } else { ModelFilelist = context.Session[SessionID] as List <Sys_ModelFile>; } Sys_ModelFile model = new Sys_ModelFile(); model.FileID = Guid.NewGuid().ToString(); model.File_Name = filename; model.File_Extension = sExtension; model.File_Size = fileLength; model.File_Path = tempPath + sNewFileName + sExtension; model.File_AddTime = DateTime.Now; model.File_OperationID = OperationID; model.File_UserID = currentUser.UserID; model.File_Type = FileType; string hz = ""; Regex r = new Regex(@"[\u4e00-\u9fa5]+"); Match mc1 = r.Match(FileType); if (mc1.Length != 0) //类别中含有汉字 { hz = "..(未归类)"; } try { postedFile.SaveAs(savepath + sNewFileName + sExtension);//保存 postedFile = null; ModelFilelist.Add(model); context.Session[SessionID] = ModelFilelist; string filename2 = model.File_Name; if (filename2.Length > 9) { Match mc = r.Match(filename2); if (mc.Length != 0) //名称中含有汉字 { filename2 = filename2.Substring(0, 7) + hz; } else { filename2 = filename2.Substring(0, 9) + hz; } } else { filename2 = filename2 + hz; } context.Response.Write("{filadd:'true',id:'" + model.FileID + "',filename:'" + model.File_Name + "',filesize:'" + fileContentLength + "',uploaddate:'" + Convert.ToDateTime(model.File_AddTime).ToString("yyyy年MM月dd日") + "',fileUrl:'" + model.File_Path + "',filetitle:'" + filename2 + "'}"); } catch { context.Response.Write("{filadd:'false',filename:'" + model.File_Name + "'}"); } } else { context.Response.Write("{filadd:'false',filename:'" + filename + "'}");//在没有业务ID时候,SessionID不能为空 } //context.Response.End(); }
/// <summary> /// 附件添加 /// </summary> /// <param name="context"></param> public void FilseAdd(HttpContext context) { string OperationID = context.Request.QueryString["OperationID"]; //业务ID string SessionID = context.Request.QueryString["SessionID"]; //SessionID string FileType = context.Request.QueryString["FileType"]; //附件的类型 SessionUserModel currentUser = context.Session["UserInfo"] as SessionUserModel; string pt = context.Request["Filename"].ToString(); HttpPostedFile postedFile = context.Request.Files["Filedata"]; //获取上传信息对象 string filename = postedFile.FileName; //获取上传的文件 名字 string tempPath = FileType == "系统必备工具" ? "/Download/" : UploadFileCommon.CreateDir("File"); //获取保存文件夹路径。 string savepath = context.Server.MapPath(tempPath); //获取保存路径 string sExtension = filename.Substring(filename.LastIndexOf('.')); //获取拓展名 int fileLength = postedFile.ContentLength; //获取文件大小 string fileContentLength = fileSizs(postedFile.ContentLength); //转换成MB,GB,TB if (!Directory.Exists(savepath)) //查看当前文件夹是否存在 { Directory.CreateDirectory(savepath); } //string sNewFileName = DESEncrypt.Encrypt(DateTime.Now.ToString("yyyyMMddhhmmsfff"));//上传后的文件名字 string sNewFileName = Guid.NewGuid().ToString(); if (OperationID != "" && SessionID != "" && OperationID != null) { List <Sys_ModelFile> ModelFilelist = null; if (context.Session[SessionID] == null) { ModelFilelist = new List <Sys_ModelFile>(); } else { ModelFilelist = context.Session[SessionID] as List <Sys_ModelFile>; } Sys_ModelFile model = new Sys_ModelFile(); model.FileID = Guid.NewGuid().ToString(); model.File_Name = filename; model.File_Extension = sExtension; model.File_Size = fileLength; model.File_Path = tempPath + sNewFileName + sExtension; model.File_AddTime = DateTime.Now; model.File_OperationID = OperationID; model.File_UserID = currentUser.UserID; model.File_Type = FileType; try { //postedFile.SaveAs(savepath + "@/" + sNewFileName + sExtension);//保存 postedFile.SaveAs(savepath + sNewFileName + sExtension);//保存 postedFile = null; ModelFilelist.Add(model); context.Session[SessionID] = ModelFilelist; string fileUrl = "/Files/Download.aspx?path=" + model.File_Path + "&filename=" + model.File_Name; context.Response.Write("{filadd:'true',id:'" + model.FileID + "',filename:'" + model.File_Name + "',filesize:'" + fileContentLength + "',uploaddate:'" + Convert.ToDateTime(model.File_AddTime).ToString("yyyy年MM月dd日") + "',fileUrl:'" + fileUrl + "',filePicUrl:'" + model.File_Path + "'}"); } catch { context.Response.Write("{filadd:'false',filename:'" + model.File_Name + "'}"); } } else { context.Response.Write("{filadd:'false',filename:'" + filename + "'}");//在没有业务ID时候,SessionID不能为空 } //context.Response.End(); }
/// <summary> /// 背景图片添加 /// </summary> /// <param name="context"></param> public void FilseAddbeijing(HttpContext context) { SessionUserModel currentUser = context.Session["UserInfo"] as SessionUserModel; string pt = context.Request["Filename"].ToString(); HttpPostedFile postedFile = context.Request.Files["Filedata"]; //获取上传信息对象 string filename = postedFile.FileName; //获取上传的文件 名字 string tempPath = "/Styles/login/beijing/"; //获取保存文件夹路径。 string savepath = context.Server.MapPath(tempPath); //获取保存路径 string sExtension = filename.Substring(filename.LastIndexOf('.')); //获取拓展名 int fileLength = postedFile.ContentLength; //获取文件大小 string fileContentLength = fileSizs(postedFile.ContentLength); //转换成MB,GB,TB if (!Directory.Exists(savepath)) //查看当前文件夹是否存在 { Directory.CreateDirectory(savepath); } //string sNewFileName = DESEncrypt.Encrypt(DateTime.Now.ToString("yyyyMMddhhmmsfff"));//上传后的文件名字 string sNewFileName = Guid.NewGuid().ToString(); string OperationID = context.Request.QueryString["OperationID"]; //业务ID string SessionID = context.Request.QueryString["SessionID"]; //SessionID string FileType = context.Request.QueryString["FileType"]; //附件的类型 if (OperationID != "" && SessionID != "" && OperationID != null) { List <Sys_ModelFile> ModelFilelist = null; if (context.Session[SessionID] == null) { ModelFilelist = new List <Sys_ModelFile>(); } else { ModelFilelist = context.Session[SessionID] as List <Sys_ModelFile>; } Sys_ModelFile model = new Sys_ModelFile(); model.FileID = Guid.NewGuid().ToString(); model.File_Name = filename; model.File_Extension = sExtension; model.File_Size = fileLength; model.File_Path = tempPath + sNewFileName + sExtension; model.File_AddTime = DateTime.Now; model.File_OperationID = OperationID; model.File_UserID = currentUser.UserID; model.File_Type = FileType; try { //postedFile.SaveAs(savepath + "@/" + sNewFileName + sExtension);//保存 postedFile.SaveAs(savepath + sNewFileName + sExtension);//保存 string url = tempPath + sNewFileName + sExtension; postedFile = null; System.Drawing.Image pic = System.Drawing.Image.FromFile(savepath + sNewFileName + sExtension); //strFilePath是该图片的绝对路径 int intWidth = pic.Width; //长度像素值 int intHeight = pic.Height; //高度像素值 if (FileType == "登陆背景图片") { if (intWidth == 1920 && intHeight == 1080) { ModelFilelist.Add(model); context.Session[SessionID] = ModelFilelist; string fileUrl = "/Files/Download.aspx?path=" + model.File_Path + "&filename=" + model.File_Name; pic.Dispose(); context.Response.Write("{filadd:'true',url:'" + url + "',id:'" + model.FileID + "',filename:'" + model.File_Name + "',filesize:'" + fileContentLength + "',uploaddate:'" + Convert.ToDateTime(model.File_AddTime).ToString("yyyy年MM月dd日") + "',fileUrl:'" + fileUrl + "'}"); } else { pic.Dispose(); File.Delete(HttpContext.Current.Server.MapPath(model.File_Path)); context.Response.Write("{filadd:'false',name:'2',filename:'请上传分辨率为1920*1080的图片'}"); } } else if (FileType == "主框架LOGO背景图片") { if (intWidth == 417 && intHeight == 50) { ModelFilelist.Add(model); context.Session[SessionID] = ModelFilelist; string fileUrl = "/Files/Download.aspx?path=" + model.File_Path + "&filename=" + model.File_Name; pic.Dispose(); context.Response.Write("{filadd:'true',url:'" + url + "',id:'" + model.FileID + "',filename:'" + model.File_Name + "',filesize:'" + fileContentLength + "',uploaddate:'" + Convert.ToDateTime(model.File_AddTime).ToString("yyyy年MM月dd日") + "',fileUrl:'" + fileUrl + "'}"); } else { pic.Dispose(); File.Delete(HttpContext.Current.Server.MapPath(model.File_Path)); context.Response.Write("{filadd:'false',name:'2',filename:'请上传分辨率为417*50的图片'}"); } } } catch { context.Response.Write("{filadd:'false',name:'1',filename:'" + model.File_Name + "'}"); } } else { context.Response.Write("{filadd:'false',name:'1',filename:'" + filename + "'}");//在没有业务ID时候,SessionID不能为空 } //context.Response.End(); }