zoukankan      html  css  js  c++  java
  • 在MVC中实现文件的上传

      @using (Html.BeginForm("daoru", "Excel", FormMethod.Post, new { enctype = "multipart/form-data" }))

            {  <input id="File1" type="file" name="FileName" />

                <input type="submit" value="导入" />

            }

    new { enctype = "multipart/form-data" }必不可少,不认上传不能成功!

    public ActionResult daoru(FormCollection form, string FileName)

            {

                //GoodsDBDataContext BDataContext = new GoodsDBDataContext();

                //清空系统缓存

                string path = Server.MapPath("~/File");

                Directory.Delete(path, true);

                Directory.CreateDirectory(path);

                //判断是否有文件

                if (Request.Files.Count == 0)

                {

                    return View("Index");

                }

                //得到上传的文件

                var file = Request.Files[0];

                if (file.ContentLength == 0)

                {

                    return View("Index");

                }

                else

                {

                    //上传文件,exc.xlsx就是你上上传的值

                    HttpPostedFileBase file1 = Request.Files[0];

                    string path1 = Path.Combine(path, "exc.xlsx");

                    file1.SaveAs(path1);

                }

    }

  • 相关阅读:
    通过静态广播监听网络变化,在通过回调通知
    支付宝九宫格
    toolBar
    QQ发送位置(高德地图)
    聊天消息 左右item
    Scrollview 嵌套 RecyclerView 及在Android 5.1版本滑动时 惯性消失问题
    判断软键盘是否弹出 并且隐藏
    Solve Longest Path Problem in linear time
    Why longest path problem doesn't have optimal substructure?
    [leetcode] Reorder List
  • 原文地址:https://www.cnblogs.com/Gold-fangjin/p/5607562.html
Copyright © 2011-2022 走看看