public static void RenderJsResource(string RsPath, string JsPath) { //var RsPath = "~//App_GlobalResources//resource1.resx"; //var JsPath = "~//common//js//abc.js"; RsPath = HttpContext.Current.Server.MapPath(RsPath); JsPath = HttpContext.Current.Server.MapPath(JsPath); var script = new StringBuilder(); using (var resourceReader = new System.Resources.ResXResourceReader(RsPath)) { foreach (DictionaryEntry entry in resourceReader) { var key = ZConvert.ToString(entry.Key).Replace('.', '_'); var value = ZConvert.ToString(entry.Value); script.Append(","); script.Append(key); script.Append(":"); script.Append('"' + value + '"'); script.Append("\r\n"); } } try { var str = "var lang = {\r\n " + script.ToString().Trim(',') + "}"; ZFiles.DeleteFiles(JsPath); ZFiles.WriteStrToTxtFile(JsPath, str, FileMode.CreateNew); } catch { } }
/// <summary> /// http文件上传 /// </summary> /// <param name="hpFile">http文件 HttpPostedFile</param> /// <param name="allowExtensions"> 允许上传的扩展文件名类型 小写,如:string[] allowExtensions = { ".doc", ".xls", ".ppt", ".jpg", ".gif" };</param> /// <param name="maxLength">允许上传的最大大小,以kb为单位</param> /// <param name="savePath">保存文件的目录,注意是绝对路径,如:Server.MapPath("~/upload/");</param> /// <param name="saveName">保存的文件名,如果是""则以原文件名保存</param> /// <returns></returns> public static ReSultMode FilesUpload(HttpPostedFile hpFile, string[] allowExtensions, int maxLength, string savePath, string saveName) { ReSultMode rsm = new ReSultMode(); string fileExtension = System.IO.Path.GetExtension(hpFile.FileName).ToLower(); bool fileAllow = false; string tmp = ""; // 存储允许上传的文件后缀名 if (allowExtensions.Length == 0) { fileAllow = true; } else { for (int i = 0; i < allowExtensions.Length; i++) { tmp += i == allowExtensions.Length - 1 ? allowExtensions[i] : allowExtensions[i] + ","; if (fileExtension == allowExtensions[i]) { fileAllow = true; } } } if (fileAllow) { if (hpFile.ContentLength / 1024 > maxLength) { rsm.code = -13; rsm.msg = "文件不能大于" + maxLength + "kB"; rsm.data = ""; } else { try { if (string.IsNullOrEmpty(saveName)) { saveName = hpFile.FileName; } ZFiles.CreateDirectoryIsExists(savePath);//不存在就创建 hpFile.SaveAs(savePath + saveName); rsm.code = 11; rsm.data = saveName; rsm.msg = "保存成功"; } catch (Exception ex) { rsm.code = -11; rsm.msg = ex.Message; rsm.data = ""; } } } else { rsm.code = -13; rsm.msg = "文件格式不符,可以上传的文件格式为:" + tmp; rsm.data = ""; } return(rsm); }