开发者

how to read an image file in asp.net c# using asp:fileupload?

开发者 https://www.devze.com 2023-02-06 14:52 出处:网络
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.

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

精彩评论

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