项目中需要多次上传文件,能不能做个通用的上传控件或通用类什么的? HttpFileCollection 类HttpFileCollection _HttpFileCollection = HttpContext.Current.Request.Files;可以接收一组集合.页面可以用javascript来添加上传控件的多少. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 example:<script type="text/javascript">function onAppend(){ var obj = $("tableImage"); var rowIndex1 = obj.childNodes[0].childNodes.length; var objTR = obj.insertRow(rowIndex1); var obj_TD_1 = objTR.insertCell(); var obj_TD_2 = objTR.insertCell(); var rowIndex2 = parseInt(rowIndex1) + parseInt(1); obj_TD_1.innerHTML = obj.childNodes[0].childNodes[rowIndex1 - 1].childNodes[0].innerHTML;}function onRemove(obj){ var n = 0; var object = document.getElementsByTagName('input'); for(var i = 0; i < object.length; i++) { if(object[i].type == 'file') { if(object[i].name == 'picinfo') { n++; } } } if(n - 1 != 0) obj.parentNode.parentNode.removeNode(true); else alert('错误:请至少保留一个选项卡!');}</script>HttpFileCollection _HttpFileCollection = HttpContext.Current.Request.Files;for (int i = 0; i < _HttpFileCollection.Count; i++){ _HttpFileCollection[i].SaveAs("path");} HTML:<table id="tableImage" width="100%" border="0" cellspacing="0" cellpadding="0" style="height:25px"> <tr> <td> <input type="file" name="picinfo" id="picinfo" style="width: 300px" runat="server" /> <input type="button" name="btn_Remove" value="添加" onclick="onAppend(this);" /> <input type="button" name="btn_Remove" value="移除" onclick="onRemove(this);" /> </td> </tr></table> <body MS_POSITIONING="GridLayout"> <form id="upMoreFile" method="post" encType="multipart/form-data" runat="server"> <asp:label id="Title" Runat="server"></asp:label> <P id="FileCollection"><INPUT type="file" name="File"> </P> <P><input onclick="addFileControl()" type="button" value="增加(File)"> <asp:button id="Upload" Runat="server" Text="上传" Width="56px"></asp:button><input style="WIDTH: 56px; HEIGHT: 24px" onclick="this.form.reset()" type="button" value="重置"> </P> <P align="center"><asp:label id="strStatus" runat="server" BorderColor="White" BorderStyle="None" Width="500px" Font-Size="9pt" Font-Bold="True" Font-Names="宋体"></asp:label></P> </form> </body>private void Upload_Click(object sender, System.EventArgs e) { upMorefile(); } private bool upMorefile() { //遍历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++) { //定义访问客户端上传文件的对象 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); //上传的文件信息 strMsg.Append("上传的文件类型:" + postedFile.ContentType.ToString() + "<br>"); strMsg.Append("客户端文件地址:" + postedFile.FileName + "<br>"); strMsg.Append("上传文件的文件名:" + fileName + "<br>"); strMsg.Append("上传文件的扩展名:" + fileExtension + "<br><hr color=red>"); //保存到指定的文件夹 postedFile.SaveAs(Server.MapPath("upedFile/") + fileName); } } strStatus.Text = strMsg.ToString(); return true; } catch(System.Exception error) { strStatus.Text = error.Message; return false; } } 先掌握.net下是如何实现文件上传的再按照自己的需求封装起来vs2005中自带的FileUpload控件实现图片文件的上传参考http://www.cnblogs.com/weekzero/archive/2006/05/05/392003.html(生成缩略图的可以不看) qinhl99 ,Nils 你们可能误会我的意思了。一个表单内要上传多个文件,如: 营业执照:上传, 产品证书:上传, 产品报告:上传, ......上传后我要得到相应的文件地址并保存到数据库,这样用2位说的方法只能是把文件上传到数据库,怎么来区分的类别并保存到数据库呢?还有比如营业执照只能上传一个文件而证书可以上传多个文件怎么控制呢? 在asp中我只须调用我上面写的upload_box函数即可。刚接触asp.net可能是我的思维还停留在asp ,迷茫...... zyug ,能不能说详细点,我刚开始学很多都不懂。 你可以参考一下那个www.tootoo.com的上传它是用内框了一个上传页面完成的 大文件的上传直接用FTP吧。asp.net默认只能上传4M的文件。必须重新配置web.config.如果是要特殊要求,干脆开发个控件专门用来上传,比如象QQ的邮箱里的文件中转站那样的。 {顶者有分}关于设计思路的思考-逻辑控件 求救!! 文档的名称或路劲无效。。。 急---在线等:淘宝的那个给星级评论怎么做的? 怎么 实现无刷新下拉框 四级联动 没一级的都要求从数据库检索来的! 请问子类如何发布父类的成员方法? 使用asp.net web site administration Tool 出错,在线等!! 树控件问题 <html> linq to sql查询问题。 当调试状态下运行一个ASP.Net的项目时会有下列错误,万望哪位高手能帮我解决这个难题! 请问DXperience控件是不是只能在CS模式下使用,在BS模式能使用吗 GridView显示DataSet修改后的信息
<script type="text/javascript">
function onAppend()
{
var obj = $("tableImage");
var rowIndex1 = obj.childNodes[0].childNodes.length;
var objTR = obj.insertRow(rowIndex1);
var obj_TD_1 = objTR.insertCell();
var obj_TD_2 = objTR.insertCell();
var rowIndex2 = parseInt(rowIndex1) + parseInt(1);
obj_TD_1.innerHTML = obj.childNodes[0].childNodes[rowIndex1 - 1].childNodes[0].innerHTML;
}function onRemove(obj)
{
var n = 0; var object = document.getElementsByTagName('input'); for(var i = 0; i < object.length; i++)
{
if(object[i].type == 'file')
{
if(object[i].name == 'picinfo')
{
n++;
}
}
} if(n - 1 != 0)
obj.parentNode.parentNode.removeNode(true);
else
alert('错误:请至少保留一个选项卡!');
}
</script>HttpFileCollection _HttpFileCollection = HttpContext.Current.Request.Files;
for (int i = 0; i < _HttpFileCollection.Count; i++)
{
_HttpFileCollection[i].SaveAs("path");
}
<tr>
<td>
<input type="file" name="picinfo" id="picinfo" style="width: 300px" runat="server" /> <input type="button" name="btn_Remove" value="添加" onclick="onAppend(this);" /> <input type="button" name="btn_Remove" value="移除" onclick="onRemove(this);" />
</td>
</tr>
</table>
<form id="upMoreFile" method="post" encType="multipart/form-data" runat="server">
<asp:label id="Title" Runat="server"></asp:label>
<P id="FileCollection"><INPUT type="file" name="File">
</P>
<P><input onclick="addFileControl()" type="button" value="增加(File)">
<asp:button id="Upload" Runat="server" Text="上传" Width="56px"></asp:button><input style="WIDTH: 56px; HEIGHT: 24px" onclick="this.form.reset()" type="button" value="重置">
</P>
<P align="center"><asp:label id="strStatus" runat="server" BorderColor="White" BorderStyle="None" Width="500px"
Font-Size="9pt" Font-Bold="True" Font-Names="宋体"></asp:label></P>
</form>
</body>
private void Upload_Click(object sender, System.EventArgs e)
{
upMorefile();
} private bool upMorefile()
{
//遍历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++)
{
//定义访问客户端上传文件的对象
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);
//上传的文件信息
strMsg.Append("上传的文件类型:" + postedFile.ContentType.ToString() + "<br>");
strMsg.Append("客户端文件地址:" + postedFile.FileName + "<br>");
strMsg.Append("上传文件的文件名:" + fileName + "<br>");
strMsg.Append("上传文件的扩展名:" + fileExtension + "<br><hr color=red>");
//保存到指定的文件夹
postedFile.SaveAs(Server.MapPath("upedFile/") + fileName);
}
}
strStatus.Text = strMsg.ToString();
return true;
}
catch(System.Exception error)
{
strStatus.Text = error.Message;
return false;
}
}
http://www.cnblogs.com/weekzero/archive/2006/05/05/392003.html(生成缩略图的可以不看)
一个表单内要上传多个文件,如:
营业执照:上传,
产品证书:上传,
产品报告:上传,
......
上传后我要得到相应的文件地址并保存到数据库,这样
用2位说的方法只能是把文件上传到数据库,怎么来区分
的类别并保存到数据库呢?还有比如营业执照只能上传一个文件
而证书可以上传多个文件怎么控制呢?
在asp中我只须调用我上面写的upload_box函数即可。
刚接触asp.net可能是我的思维还停留在asp ,迷茫......
它是用内框了一个上传页面完成的
如果是要特殊要求,干脆开发个控件专门用来上传,比如象QQ的邮箱里的文件中转站那样的。