11-UploadFile

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;
}
}

posted @ 2018-11-22 20:32  萌新赖  阅读(265)  评论(0编辑  收藏  举报