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

                }

    }

  • 相关阅读:
    ALV_TREE(二:cl_gui_simple_tree…
    ALV_TREE(一:cl_gui_alv_tree_si…
    SQLPlus命令详细说明
    PL/SQL中,declare定义变量和variable定义变量的区别?
    Oracle 多表视图更新(待看完触发器后再来看)
    Oracle 函数 Translate 的用法
    Merge into
    savepoint(回退点)
    Oracle之分页查询
    对于package中全局变量的一点点初级理解
  • 原文地址:https://www.cnblogs.com/Gold-fangjin/p/5607562.html
Copyright © 2011-2022 走看看