Display an image from Fileupload control?

Posted by Anilkumar431 under ASP.NET on 6/3/2013 | Points: 10 | Views : 930 | Status : [Member] | Replies : 2
hi guys,
i need to display an image in an image control immediately after uploading from Fileupload control..
please help me.
thanx in advance....




Responses

Posted by: Santhi on: 6/4/2013 [Member] Starter | Points: 25

Up
0
Down
Hi

Try this code...
You have to save the file to the server..
Then you can show it..
code

      protected void Button1_Click(object sender, EventArgs e)

{
if (FileUpload1.HasFile)
{
FileUpload1.SaveAs(Server.MapPath("img").ToString() + @"\" + FileUpload1.FileName);
Image1.ImageUrl = @"~\img\" + FileUpload1.FileName;
}
}

Design page
<div>

<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Image ID="Image1" runat="server" Height="100px" Width="100px" />
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />

</div>


Thanks & Regards,
Santhi .V

Anilkumar431, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Anilkumar431 on: 6/5/2013 [Member] Starter | Points: 25

Up
0
Down
Thanx santhi .
it's working....

Anilkumar431, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response