/// <summary> /// 读取单个图片资源本地配置 /// </summary> /// <param name="lcid"></param> /// <returns></returns> public WXPictureResultJson LoadResourcesSingleBylcId(int lcid) { WXPictureResultJson pResult = null; this.ExecuteTryCatch(() => { //获取配置,并匹配实体集合 List <WXPictureResultJson> pList = base.LoadResourcesX <WXPictureResultJson>(m_strTargetType); pResult = pList.Single(p => p.lcId == lcid); }); return(pResult); }
/// <summary> /// 从请求中加载上传文件 /// </summary> /// <param name="pRequest"></param> /// <param name="pInputFileName"></param> /// <param name="pServerPath"></param> /// <returns></returns> protected void LoadFileFromRequest(HttpRequestBase pRequest, string pInputFileName, string pServerPath, ref WXPictureResultJson pResult) { //定义错误消息 string msg = ""; //接受上传文件 HttpPostedFileBase hp = pRequest.Files[pInputFileName]; if (hp == null) { msg = "请选择文件"; EGExceptionOperator.ThrowX <Exception>(msg, EGActionCode.缺少必要参数); } //获取上传目录 转换为物理路径 string uploadPath = System.Web.HttpContext.Current.Server.MapPath(pServerPath); //获取文件名 string fileName = DateTime.Now.Ticks.ToString() + System.IO.Path.GetExtension(hp.FileName); //获取文件大小 long contentLength = hp.ContentLength; //文件不能大于1M if (contentLength > 1024 * 1024) { msg = "文件大小超过限制要求."; EGExceptionOperator.ThrowX <Exception>(msg, EGActionCode.输入参数错误); } if (!checkFileExtension(fileName)) { msg = "文件为不可上传的类型."; EGExceptionOperator.ThrowX <Exception>(msg, EGActionCode.输入参数错误); } //保存文件的物理路径 string saveFile = uploadPath + fileName; try { //保存文件 hp.SaveAs(saveFile); //写入绝对路径 pResult.APath = saveFile; //写入相对路径 pResult.RPath = pServerPath + fileName; //写入文件名称 pResult.FileName = fileName; //msg = saveFile; //msg = pServerPath + fileName; } catch { msg = "图片文件上传失败"; EGExceptionOperator.ThrowX <Exception>(msg, EGActionCode.文件上传失败); } //return msg; }