日期:2014-05-20  浏览次数:20403 次

为什么我的机器上这样用HttpFileCollection 取不到上传文件呢?
代码如下:
   
<INPUT   id= "MFileUpLoadaa "   type= "file "   runat= "server ">
<asp:Button   id= "Button1 "     runat= "server "   Text= "Button "> </asp:Button>

private   void   Button1_Click(object   sender,   System.EventArgs   e)
{
HttpFileCollection   files   =   HttpContext.Current.Request.Files;
Response.Write(files.Count.ToString());
}
输出老是零,实在找不出原因。
但是在我同事上这段代码运行没有问题,难道我机器那些地方还要配置?


------解决方案--------------------
form 那里要加上 enctype= "multipart/form-data "

如果你使用了 <asp:FileUpload runat=server> ,那么enctype就会自动加上
------解决方案--------------------
多个文件上传的话
form 中应该写上 enctype= "multipart/form-data "
单个文件的话
直接
if (MFileUpLoadaa.PostedFile.ContentLength > 0)
{
fileName = fileADPic.PostedFile.FileName;
... }
}
------解决方案--------------------
代码上没有什么问题,也不用什么设置啊,楼主是不是其它地方搞错了?
------解决方案--------------------
使用httpdebug跟踪一下客户端发送的数据,先判断是否已经发送
然后在判断服务器端是否已经接收
------解决方案--------------------
关注,没弄过。
------解决方案--------------------
确保表单中有:
... enctype= "multipart/form-data " ...