• 上传图片后台写法


    [HttpPost]

            public ActionResult UpFile()

            {

     

     

                int count = Request.Files.Count;

     

     

                for (int i = 0; i < count; i++)

                {

                    WebTest.Entity.FileInfo fileInfo = new WebTest.Entity.FileInfo();

                    HttpPostedFileBase file = Request.Files[i];

                    string[] NameTpye = file.FileName.Split(new char[] { '.' });

              

                    string Path = "/Image/UpWord/" + DateTime.Now.ToString("yyyyMMddHHmmssffff");

                    string FilePath = Server.MapPath(Path);

                    if (!Directory.Exists(FilePath))

                    {

                        Directory.CreateDirectory(FilePath);

                    }

                    file.SaveAs(FilePath + "/" + file.FileName);

     

                    fileInfo.FileName = NameTpye[0];

                    fileInfo.FileType = "." + NameTpye[1];

                    fileInfo.FileUrl = Path + "/" + file.FileName;

                    fileInfo.Refnum = 1;

                    fileInfo.RefnumTable = "News";

                    fileInfo.Size = (file.ContentLength / 1024).ToString();

     

                    db.Set<WebTest.Entity.FileInfo>().Add(fileInfo);

     

                }

                int res = db.SaveChanges();

     

                if (res > 0)

                {

                    return Content("OK:上传文件成功!");

                }

                else

                {

                    return Content("NO:上传文件失败!");

                }

            }

    NET新手,希望各位大侠多多指教。
  • 相关阅读:
    html基础进阶笔记
    程序员的自我提升
    过滤思路
    for循环
    jeesite在生成主子表代码的时候在eclipse里面没有子表代码
    java学习笔记2
    人性的弱点
    java学习笔记
    Percona Toolkit 安装使用
    mysql 中查询当天、本周,本月,上一个月的数据
  • 原文地址:https://www.cnblogs.com/duanyuerui/p/6901642.html
Copyright © 2020-2023  润新知