<style type="text/css">
        .delete_attach
        {
            padding-left: 18px;
            background: url(../image/delete.png) no-repeat left top;
            margin-left: 7px;
            width: 90px;
            color: #002f76;
        }
        .add_attach
        {
            padding-left: 22px;
            background: url(../image/add.png) no-repeat left center;
            width: 90px;
            color: #002f76;
        }
    </style>
    <script type="text/javascript">
        var MAXFILES = 10;        //文件计数器
        var fileCount = 0;
        function addAttach(noAlert) {
            if (fileCount >= MAXFILES && !noAlert) { alert("最多只能添加" + MAXFILES + "个附件!"); return; }
            var fileSectionDiv = document.getElementById("files");
            var fileItemDiv = document.createElement("div");
            fileCount++;
            var content = "<input type='file' onchange='return addAttach(true);' id=='fileUpload'" + fileCount + " name='fileUpload'" + fileCount + ">&nbsp;<a href='#' onclick='return delAttach(\"" + fileCount + "\")' class='delete_attach' >移除附件</a>";
            fileItemDiv.id = "fileItemDiv" + fileCount;
            fileItemDiv.innerHTML = content;
            fileSectionDiv.appendChild(fileItemDiv);
            return false;
        }

function delAttach(fileIndex) {
            var fileSectionDiv = document.getElementById("files");
            var fileItemDiv = document.getElementById("fileItemDiv" + fileIndex);
            fileSectionDiv.removeChild(fileItemDiv);
            fileCount--;
            return false;
        }   
    </script>

<form id="form1" runat="server" method="post" enctype="multipart/form-data">

<a id="addAttach_a" onclick="return addAttach(false);" href="#" class="add_attach">添加附件</a>
                            <div id="files" runat="server">
                            </div>

</form>

string file = "Files";
            string path = Server.MapPath(file);
            if (!System.IO.Directory.Exists(path))//判断文件夹是否已经存在
            {
                System.IO.Directory.CreateDirectory(path);//创建文件夹
            }
            for (int index = 0; index < Request.Files.Count; index++)
            {
                if (!string.IsNullOrEmpty(Request.Files[index].FileName))
                {
                    string NewName = DateTime.Now.ToString("yyyyMMddHHmmss") + rd.Next(10000, 99999);
                    string Extension = Path.GetExtension(Request.Files[index].FileName);
                    Request.Files[index].SaveAs(Path.Combine(path, NewName + Extension));
                    details.Add(new AdvertiseDetail
                    {
                        Id = Utils.CreateGUID(),
                        FileName = file,
                        NewName = NewName + Extension,
                        OldName = System.IO.Path.GetFileName(Request.Files[index].FileName),
                        CreatedByID = "1001",
                        CreatedDate = DateTime.Now,
                        LastModifiedByID = "1001",
                        LastModifiedDate = DateTime.Now
                    });
                }
            }

最新文章

  1. 夺命雷公狗----Git---7---GitHub当仓库本地使用(完)
  2. SQL注入的字符串连接函数
  3. deep learning 练习 多变量线性回归
  4. 高性能JavaScript(您值得一看)
  5. Javascript 封装方法
  6. Error:&ldquo;应用程序无法正常启动(0xc000007b)。请单击&ldquo;确定&rdquo;关闭应用程序。&rdquo;
  7. ArcGIS 点到直线的距离
  8. MyBatis中的特殊符号[20160713]
  9. web医疗影像浏览demo及地址
  10. 第16章 观察者模式(Oberver Pattern)
  11. Git提交到多个远程仓库
  12. 几道数位DP
  13. Hadoop基础知识串烧
  14. Hadoop-2.7.3-src 源码编译
  15. 【Python 23】52周存钱挑战3.0(循环计数for与range)
  16. SSM框架中常用的配置文件
  17. linux bash timeout
  18. 使用Eclipse的坑
  19. Mybatis 系列1-环境搭建
  20. 跟我学SharePoint 2013视频培训课程—— 版本控制以及内容审批(14)

热门文章

  1. git学习:多人协作,标签管理
  2. varnish 4.0.3 域名访问的小问题
  3. 错误 1 error C4996: &#39;scanf&#39;: This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. d:\users\vs2013\le
  4. shell script
  5. Windows服务定时执行方式
  6. Linux常见命令
  7. Java创建WebService服务及客户端实现(转)
  8. LAMP_02_WIN下Apache安装配置
  9. nyoj 142, poj 1039 ,hdu 1454 管道问题
  10. STL之set