多图片上传时如何给每张图片添加描述信息---散分题
我找了好多,都跟我的不符合
麻烦大家了
HTML-------------------------
<%@ Page Language= "C# " AutoEventWireup= "true " CodeFile= "Default.aspx.cs " Inherits= "_Default " %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN " "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml ">
<head runat= "server ">
<title> 多文件上传 </title>
<script language= "JavaScript ">
function addFile()
{
var str = ' <INPUT type= "file " size= "200px " NAME= "File "> '
var strtxt= ' <input type= "text " size= "100px " name= "txtFile " /> '
document.getElementById( 'MyFile ').insertAdjacentHTML( "beforeEnd ",str)
document.getElementById( 'MyFile ').insertAdjacentHTML( "beforeEnd ",strtxt)
}
</script>
</head>
<body>
<form id= "form1 " runat= "server ">
<asp:ScriptManager ID= "ScriptManager1 " runat= "server " />
<div>
<h3> 多文件上传 </h3>
<P id= "MyFile " style= "background-color:Burlywood;width:400px ">
<INPUT id= "fileLoad " type= "file " runat= "server " NAME= "File "> <br />
图片描述: <input id= "txtCaption " type= "text " name= "txtFile " runat= "server " />
</P>
<P>
<input type= "button " value= "增加(Add) " onclick= "addFile() ">
<input onclick= "this.form.reset() " type= "button " value= "重置(ReSet) ">
<asp:Button Runat= "server " Text= "开始上传 " ID= "UploadButton " OnClick= "UploadButton_Click "> </asp:Button>
</P>
<P>
<asp:Label id= "strStatus " runat= "server " Font-Names= "宋体 " Font-Bold= "True " Font-Size= "9pt "
Width= "500px " BorderStyle= "None " BorderColor= "White "> </asp:Label>
</P>
</div>
</form>
</body>
</html>
----------------------.CS
private Boolean SaveImages()
{
/// '遍历上传File表单元素
HttpFileCollection files = HttpContext.Current.Request.Files;
////获取 描述信息File 表单元素
//int txtfiles = HttpContext.Current.Request.Files.Count;
/// '状态信息
System.Text.StringBuilder strMsg = new System.Text.StringBuilder();
strMsg.Append( "上传的文件分别是: <hr color=red> ");
try
{
for (int iFile = 0; iFile < files.Count; iFile++)
{
/// '检查文件扩展名字
HttpPostedFile postedFile = files[iFile];
string fileName, fileExtension;
fileName = System.IO.Path.GetFileName(postedFile.FileName);
if (fileName != " ")
{
fileExtension = System.IO.Path.GetExtension(fileName);
strMsg.Append( "上传图片的描述: " + ?????????????? + " <br> ");
strMsg.Append( "上传文件的描述: " + txtCaption.Value + " <br> ");
strMsg.Append( "上传的文件类型: " + postedFile.ContentType.ToString() + " <br> ");
strMsg.Append( "客户端文件地址: " + postedFile.FileName + " <br> ");
strMsg.Append( "上传文件的文件名: " + fileName + " <br> ");
strMsg.Append( "上传文件的扩展名: " + fileExtension + " <br> <hr> ");
/// '可根据扩展名字的不同保存到不同的文件夹
///注意:可能要修改你的文件夹的匿名写入权限。
postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath( "images/ ") + fileName);
}
}
strStatus.Text = strMsg.ToString();
return true;
}
catch (System.Exception Ex)
{
strStatus.Text = Ex.Message;
return false;
}
}
--------------------------------提问
strMsg.Append( "上传图片的描述: " + ?????????????? + " <br> ");
在循环获取图片路径、名称、扩展名到时候怎么获取相对应的图片描述信息,,
就是如何获取txtCaption中的内容,代码放在问号处
<input id= "txtCaption " type= "text " name= "txtFile " runat= "server " />
---------------谢谢大家了
[解决办法]
顶顶顶,呵呵