zoukankan      html  css  js  c++  java
  • 上传图片后台写法

    [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新手,希望各位大侠多多指教。
  • 相关阅读:
    设计模式浅谈
    链表的遍历(1)
    链表的删除(3)
    链表结构的反转(5)
    二叉树数组表示法
    循环链表的插入和删除
    链表的链接(2)
    双向链表内结点的删除(4)
    hdu1042
    数组和链表的区别
  • 原文地址:https://www.cnblogs.com/duanyuerui/p/6901642.html
Copyright © 2011-2022 走看看