/// <summary> /// 保存文件(限定保存目录) /// </summary> public static string SaveFile(string vpath, string fileName, byte[] file) { DirPathDel(ref vpath); if (FileNameCheck(fileName) || !VPathCheck(vpath)) { throw new Exception(vpath + fileName + "保存失败,不符合命名规范!"); } string dirPath = IOPath.VToP(vpath.TrimEnd('/') + "/"); CreateDir(dirPath, ""); File.WriteAllBytes(dirPath + fileName, file); return(IOPath.PToV(dirPath + fileName)); }
/// <summary> /// 允许写入JS与html,config等文件 /// </summary> /// <param name="vpath"></param> /// <param name="content"></param> /// <returns></returns> public static string WriteUnSafeFile(string vpath, string content) { string name = ""; string path = ""; IOPath.GetNameAndPath(vpath, out name, out path); DirPathDel(ref vpath); string dirPath = IOPath.VToP(vpath); //if (SafeC.FileNameCheck(new string[1] { fileName }) || !SafeC.VPathCheck(vpath)) { throw new Exception(vpath + fileName + "保存失败,不符合命名规范!"); } CreateDir(dirPath, ""); string ppath = dirPath + name; byte[] bytes = Encoding.UTF8.GetBytes(content); File.WriteAllBytes(ppath, bytes); return(IOPath.PToV(ppath)); }