首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

VS2005 asp.net(C#)上传有关问题. -寻找CSDN牛人

2012-02-19 
VS2005 asp.net(C#)上传问题.---寻找CSDN牛人各位强淫:小弟最近做asp.netC#的上传时,有问题一直解决不了,

VS2005 asp.net(C#)上传问题. ---寻找CSDN牛人
各位强淫:
小弟最近做asp.net   C#的上传时,有问题一直解决不了,各位牛人帮忙啊.
aspx内部分代码:
        <title> 多文件上传 </title>  
        <script   language= "JavaScript ">  
        function   addFile()  
        {  
          var   str   =   ' <INPUT   type= "file "   size= "50 "   NAME= "File "> '  
          document.getElementById( 'MyFile ').insertAdjacentHTML( "beforeEnd ",str)  
        }  
        </script>  

        <form   id= "form2 "   method= "post "   runat= "server "   enctype= "multipart/form-data ">  
            <div   align= "center ">  
                <h3> 多文件上传 </h3>  
                <P   id= "MyFile "> <INPUT   type= "file "   size= "50 "   NAME= "File "> </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 "> </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>  

aspx.cs内部分代码:
                /// '遍历File表单元素  
                HttpFileCollection   files   =   HttpContext.Current.Request.Files;

新建工程,上面的files是有值的.但放在自己的工程里,files的COUNT一直是0,
怎么回事啊?各位帮帮忙.

[解决办法]
//--刚才测试了下没问题啊. 估计是你代码中其他地方有问题.

<%@ Page Language= "C# " AutoEventWireup= "true " CodeFile= "testMoreUpload.aspx.cs " Inherits= "testMoreUpload " %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.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= "50 " NAME= "File "> '
document.getElementById( 'MyFile ').insertAdjacentHTML( "beforeEnd ",str)
}
</script>
</head>
<body>
<form id= "form1 " runat= "server " enctype= "multipart/form-data ">
<div align= "center ">
<h3> 多文件上传 </h3>
<P id= "MyFile "> <INPUT type= "file " size= "50 " NAME= "File "> </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

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class testMoreUpload : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void UploadButton_Click(object sender, EventArgs e)
{
HttpFileCollection files = HttpContext.Current.Request.Files;
Response.Write(files.Count);
}
}

[解决办法]
天啊..updatepanel不支持这个..这个官方文档早就出了....解决的方法是把它放在 <iframe> 里面..

热点排行