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();

  • 相关阅读:
    你的灯亮着么阅读笔记2
    你的灯亮着么阅读笔记1
    梦断代码阅读笔记3
    梦断代码阅读笔记2
    梦断代码阅读笔记1
    百度搜索分析
    有多少1
    寻找“水王”问题
    站立会议
    买书的最低价格问题
  • 原文地址:https://www.cnblogs.com/zhang102137/p/8384145.html
Copyright © 2011-2022 走看看