最好的多附件上传,无私奉献了!

    <script language="javascript" type="text/javascript">
        function addFileControl()
        {
            var index = parseInt(document.getElementById("Hidden1").value,typeof(int));
            addFile(index);
        }
        function addFile(index)
        {
            var str = "<input type = 'file' id = 'file" + index + "' name = 'File' style='width: 350px'/><input type='button' id='button" + index +"' οnclick='delFileControl(" + index + ");' value='删除' class='cmd_defaultsmall'/>";
            document.getElementById("fileList").insertAdjacentHTML("beforeEnd",str);
            document.getElementById("Hidden1").value = eval(index + 1);
        }
        function delFileControl(index)
        {
            document.getElementById("fileList").removeChild(document.getElementById("file" + index));
            document.getElementById("fileList").removeChild(document.getElementById("button" + index));
        }
    </script>                                           

 <table border="0" cellpadding="0" cellspacing="0" width="744" class="table_main_2"                   style="background-color: white">
                                                <tr>
                                                    <td align="right" colspan="2" rowspan="1" style="height: 5px">
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td align="right" rowspan="2">
                                                        附件:</td>
                                                    <td rowspan="1">
                                                        <table cellpadding="0" cellspacing="0" width="100%" id="tblAttachFile" runat="server">
                                                            <tr>
                                                                <td>
                                                                    <div id="fileList0" runat="server" style="width: 531px">
                                                                    </div>
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td>
                                                                    <input id="Button1" class="cmd_defaultsmall" οnclick="addFileControl('fileList0')"
                                                                        type="button" value="增加附件" /><asp:Button ID="btnSaveFile" runat="server" CssClass="cmd_defaultsmall"
                                                                            OnClick="btnSaveFile_Click" Text="上传" /></td>
                                                            </tr>
                                                        </table>
 

 

 

    /// <summary>
    /// 上传选定的文件的具体实现
    /// </summary>
    /// <returns></returns>
    private bool UpMoreFile()
    {
        System.Web.HttpFileCollection files = System.Web.HttpContext.Current.Request.Files;
        OA.Layout.Entities.OALayoutLicence layoutLicence = ReturnLayoutLicence();

        try
        {
            string fileName, physicalPath;

            physicalPath = Server.MapPath(UploadRoot + SUBPATHROOT + @"/" + layoutLicence.ApplyID.ToString());
            System.IO.Directory.CreateDirectory(physicalPath);
            for (int i = 0; i < files.Count; i++)
            {
                System.Web.HttpPostedFile postedFile = files[i];
                fileName = System.IO.Path.GetFileName(postedFile.FileName).Replace(" ", "");
                if (fileName != string.Empty)
                {
                    OA.Layout.Entities.OALayoutLicenceC layoutLicenceCFiles = new OA.Layout.Entities.OALayoutLicenceC();
                    layoutLicenceCFiles.FileName = fileName;
                    layoutLicenceCFiles.Path = SUBPATHROOT + @"/" + layoutLicence.ApplyID.ToString() + "//" + fileName;


                    if (layoutLicence.OALayoutLicenceCCollection.Find("FileName", layoutLicenceCFiles.FileName) != null)
                    {
                        WriteJSToClient("<script language=javascript>alert('附件名称重复!请重新上传附件!');</script>");
                        continue;
                        //return false;
                    }
                    layoutLicence.OALayoutLicenceCCollection.Add(layoutLicenceCFiles);
                    postedFile.SaveAs(physicalPath + @"/" + fileName);
                }
            }
            Save();
        }
        catch (Exception ex)
        {
            ShowMessage("上传失败:" + Server.HtmlEncode(ex.Message));
            return false;
        }
        return true;

    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值