![](/img/trans.png)
[英]How to get file name from asp:FileUpload and display in a Label using ASP.NET and C#
[英]how to read an image file in asp.net c# using asp:fileupload?
我使用下面的代碼上傳圖片。 請讓我知道為什么這段代碼根本不起作用。 我還使用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在帶有ajax回發的UpdatePanel中不起作用。 要使其正常工作,您必須將btnMemberInfo注冊為PostBackTrigger才能進行完整的回發。 這樣就可以了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.