zoukankan      html  css  js  c++  java
  • 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;
    }
    }

  • 相关阅读:
    学习篇之String()
    js之Math对象
    js之date()对象
    css之描点定位方式
    js详解之作用域-实例
    js精要之构造函数
    js精要之继承
    js精要之模块模式
    js精要之对象属性
    js精要之函数
  • 原文地址:https://www.cnblogs.com/Wangyang11/p/10003736.html
Copyright © 2011-2022 走看看