2011-01-26 94 views
0

我使用下面的代码上传图片。请让我知道为什么这个代码根本不起作用。我也使用updatePanal和multiview控件来控制标签。如何读取asp.net中的图像文件c#使用asp:fileupload?

<asp:FileUpload ID="fuPhoto" runat="server"/> 
<div style="margin-top:20px;text-align:center;"> 
    <asp:Button ID="btnAddMemberInfo" runat="server" Text="Add" Width="100px" onclick="btnAddMemberInfo_Click" />         
</div> 

public byte[] GetPhtoStream() 
      { 
       byte[] bufferPhoto = new byte[fuPhoto.PostedFile.ContentLength]; 
       Stream photoStream = fuPhoto.PostedFile.InputStream; 
       photoStream.Read(bufferPhoto, 0, fuPhoto.PostedFile.ContentLength); 
       return bufferPhoto; 
      } 
protected void btnAddMemberInfo_Click(object sender, EventArgs e) 
     { 
    Photo = GetPhtoStream(); //Photo represent for the database field which datatype is image 
} 

回答

0

FileUpload在带有ajax回发的UpdatePanel中不起作用。为了得到它的工作你必须注册btnMemberInfo作为PostBackTrigger的完整回发。然后它会工作。