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

  • Post author:
  • Post category:其他



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

}



版权声明:本文为codeofsea原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。