2012-03-18
<script>
function AddAttachments()
{
document.getElementById('attach').innerText = "继续添加附件";
tb = document.getElementById('attAchments');
newRow = tb.insertRow();
newRow.insertCell().innerHTML = "<input name='File' size='50' type='file'> <input type=button value='删除' onclick='delFile(this.parentElement.parentElement.rowIndex)'>";
}
function delFile(index)
{
document.getElementById('attAchments').deleteRow(index);
tb.rows.length > 0?document.getElementById('attach').innerText = "继续添加附件":document.getElementById('attach').innerText = "添加附件";
}
</script>
<TR id="tr2" runat="server">
<TD style="BORDER-BOTTOM: #c1c1c1 1px solid"
height=30>
<DIV align=right><FONT
color=#666666><strong>上传附件:</strong> </FONT></DIV></TD>
<TD style="BORDER-BOTTOM: #c1c1c1 1px solid">
<div><table id="attAchments"></table></div><span></span>
<A id="attach" style="font-family:宋体;font-size:9pt;" title="如果您要发送多个附件,您只需多次点击“继续添加附件”即可, 要注意附件总量不能超过发送限制的大小。" onclick="AddAttachments();"
href="javascript:;" name="attach">添加附件</A>
<font color="red">(请上传附件,只能上传.doc,docx)</font>
</TD>
</TR>
//上传附件
string filePath = "";
string traget = "";
string[] files = new string[Request.Files.Count];
for (int i = 0; i < Request.Files.Count; i++)
{
if (Request.Files[i].ContentLength > 0)
{
filePath = Request.Files[i].FileName;//上传的原地址
if (System.IO.Path.GetExtension(filePath).ToString().ToLower() == ".doc" || System.IO.Path.GetExtension(filePath).ToString().ToLower() == ".docx")
{
traget = Server.MapPath("../upload/") + filePath.Substring(filePath.LastIndexOf("\\") + 1);
if (File.Exists(traget))
{
Thread.Sleep(10);
Random ran = new Random();
traget = Server.MapPath("../upload/") + filePath.Substring(filePath.LastIndexOf("\\") + 1).Replace(".", System.DateTime.Now.ToString("yyyyMMddhhmmssms") + ran.Next(1000).ToString() + ".");
}
files[i] = traget;
File.Copy(filePath, traget);
}
else
{
// Response.Write("");
this.Page.RegisterStartupScript("", "<script>alert('只能上传doc或是.docx文件!');</script>");
return;
}
}
}
for (int j = 0; j < files.Length; j++)
{
orderServiceListBLL.Insert(OrderSerid, ServiceType, userCode, orderDate, address, zipCode, phoneNumBer, realName, fax, unitName, ProvisionDate, OrderState, files[j], note, addPrice, p);
}