zoukankan      html  css  js  c++  java
  • mvc后台上传

    public ActionResult AddEnclosure(HttpPostedFileBase Filedata)
    {
    if (Filedata == null || string.IsNullOrEmpty(Filedata.FileName) || Filedata.ContentLength == 0)// 没有文件上传,直接返回
    {
    return HttpNotFound();
    }
    //利用InputStream 属性直接从HttpPostedFile对象读取文本内容
    System.IO.Stream MyStream;
    int FileLen;
    FileLen = Filedata.ContentLength;
    // 读取文件的 byte[]
    byte[] bytes = new byte[FileLen];
    MyStream = Filedata.InputStream;
    MyStream.Read(bytes, 0, FileLen);
    // 保存文件到服务器
    string strUrl = System.Web.HttpContext.Current.Server.MapPath(@"/FileBin/" + Path.GetFileName(Filedata.FileName));// 设置需要保存的地址
    System.IO.FileStream fs = new System.IO.FileStream(strUrl, System.IO.FileMode.Create, System.IO.FileAccess.Write);
    System.IO.BinaryWriter bw = new System.IO.BinaryWriter(fs);
    bw.Write(bytes);
    bw.Flush();
    fs.Flush();
    bw.Close();
    fs.Close();

  • 相关阅读:
    2019春招面试题总结-03
    2019春招面试题总结-02
    2019春招面试题总结-01
    Node.js 全局对象
    Node.js 路由
    Node.js 函数
    Node.js 模块系统
    Node.js Stream(流)
    Node.js Buffer(缓冲区)
    Node.js EventEmitter
  • 原文地址:https://www.cnblogs.com/zhang102137/p/8384145.html
Copyright © 2011-2022 走看看