11-UploadFile

mac2022-06-30  73

public class UploadFiles { /// <summary> /// 公用上传文件方法 /// </summary> /// <returns>上传后的文件完整路径</returns> public static string UpLoadFile(HttpPostedFileBase getFile) { if (getFile != null) { string getPath = System.Web.HttpContext.Current.Server.MapPath("~\\Image\\"); if (!Directory.Exists(getPath)) { Directory.CreateDirectory(getPath); } string newPath = Path.Combine(getPath, getFile.FileName); getFile.SaveAs(newPath); return "/Image/" + getFile.FileName; } else { return ""; } }

public string ReadFile(string FName) { string FilePath = System.Web.HttpContext.Current.Server.MapPath("Files" + FName); FileStream fs = new FileStream(FilePath, FileMode.Open, FileAccess.Read); StreamReader sr = new StreamReader(fs); string Content = sr.ReadToEnd(); sr.Close(); fs.Close(); return Content; } }

转载于:https://www.cnblogs.com/Wangyang11/p/10003736.html

相关资源:JAVA上百实例源码以及开源项目
最新回复(0)