开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜