[英]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.
我还使用updatePanal和multiview控件进行标签控制。
<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
}
FileUpload doesn't work in UpdatePanel with ajax postbacks. FileUpload在带有ajax回发的UpdatePanel中不起作用。 To get it work You have to register btnMemberInfo as PostBackTrigger for full postback.
要使其正常工作,您必须将btnMemberInfo注册为PostBackTrigger才能进行完整的回发。 Then it'll work.
这样就可以了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.