这里只是把主要代码给了出来,要自己研究一下,欢迎和我一起研究一下!
这个是在dw中实现的动态添加附件,可以在asp.net中直接用
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- JavaScript 实现动态增加、删除表单域 -->
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<SCRIPT LANGUAGE="JavaScript">
function Add()
{
var temp = document.body.children.item('sss').children.item(0);
temp.insertRow(temp.rows.length);
temp.rows.item(temp.rows.length -1).insertCell(0);
var xx=temp.rows.length -1 ;//-1
var sHTML
sHTML=' <tr> <td><label> <input type="file" name="file"> </label><input type=\"button\" value=\" 删除 \" onclick=\"Delete(this);\"></td> </tr>'
temp.rows.item(temp.rows.length - 1).cells.item(0).innerHTML=sHTML;
temp.rows.item(temp.rows.length-1).cells.item(0).children.item(1).text = xx;
}
function Delete(x)
{
var temp = document.body.children.item('sss').children.item(0);
temp.deleteRow(x.text.valueOf());
for (var j=1;j<temp.rows.length;j++)
temp.rows.item(temp.rows.length-1).cells.item(0).children.item(1).text=j;
}
</SCRIPT>
</HEAD>
<BODY>
<INPUT TYPE="button" value=" 添加 " onClick="Add()">
<TABLE align=center border=1 width="100%" height="100%" id="sss">
<TR id="t1">
<TD width="46%" align="center" id="tt1"> </TD>
<TD width="54%" height="251" align="center" id="tt1">
<label><input type="file" name="file"></label></TD>
</TR>
</TABLE>
</BODY>
</HTML>
这个是用来读取上传文件信息的asp.net代码
private string upMorefile()
{
//FileUpload nn = Request.Form["File0"];
//Response.Write(nn.FileName.ToString());
string strtemp = null;
//遍历File表单元素
System.Web.HttpFileCollection files = System.Web.HttpContext.Current.Request.Files;
//状态信息
System.Text.StringBuilder strMsg = new System.Text.StringBuilder("上传的文件信息分别为:<hr color=red>");
int fileCount;
int filecount = files.Count;
try
{
for (fileCount = 0; fileCount < files.Count; fileCount++)
{
//定义访问客户端上传文件的对象
int flag = fileCount;
System.Web.HttpPostedFile postedFile = files[fileCount];
string fileName, fileExtension;
//取得上传得文件名
fileName = System.IO.Path.GetFileName(postedFile.FileName);
if (fileName != String.Empty)
{
fileExtension = System.IO.Path.GetExtension(fileName);
postedFile.SaveAs("D:\\" + fileName);
if (flag == 0)
{
strtemp += fileName + "|" + fileExtension;
}
else
{
strtemp += "/" + fileName + "|" + fileExtension;
}
}
}
return strtemp;
}
catch
{
return strtemp;
}
}