how to read an image file in asp.net c# using asp:fileupload?
I used the code below for upload an image. Please let me know that why this code does not work at all. I am also using updatePanal and multiview control for tab controlling.
<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;
开发者_如何学Python }
protected void btnAddMemberInfo_Click(object sender, EventArgs e)
{
Photo = GetPhtoStream(); //Photo represent for the database field which datatype is image
}
FileUpload doesn't work in UpdatePanel with ajax postbacks. To get it work You have to register btnMemberInfo as PostBackTrigger for full postback. Then it'll work.
精彩评论