Click here to Skip to main content
15,894,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have one file upload. and button and a image on a page.I want to show the image as soon as upload button is clicked.the image is the same page.The coding is as follows
C#
protected void Button1_Click(object sender, EventArgs e)
   {
       String fn1 = Guid.NewGuid() + FileUpload1.FileName.Substring(FileUpload1.FileName.LastIndexOf("."));
       String sp1 = Server.MapPath(".");
       sp1 += "\\" + fn1;
       FileUpload1.PostedFile.SaveAs(sp1);
       Image1.ImageUrl = sp1;
   }

It is not reading the image but image icon comes on the image control.
I have used small images as well as large.
it is not showing anything
Posted
Updated 28-Nov-10 16:47pm
v3

Hello Aksh@169,

to show the uploaded image in the image control, you can replace you last line from this line :

C#
Image1.ImageUrl = FileUpload1.PostedFile.FileName;


This will do the bit you require.


Please accept answer if this was helpful.

Anurag
 
Share this answer
 
v3
Comments
Aksh@169 29-Nov-10 22:40pm    
STILL IMAGE ICON IS COMING BUT NO IMAGE.....FIRSTLY THERE IS A X ON THE IMAGE...AFTER UPLOADING BTN CLK....IT CHANGES TO ICON OF IMG VERY SMALL....NOT SHOWING ANY IMAGE
@nuraGGupta@ 29-Nov-10 22:58pm    
This is a single line code which is working fine at my end. Try it again by setting the height width of your image control.
Aksh@169 3-Dec-10 11:54am    
Any other method..sorry i am not getting image just a small image like icon on the left topmost corner.. ..any other methos
you can use given code to display image just after upload image in your web page.

string path = Server.MapPath("./") + FileUpload1.PostedFile.FileName;
      FileUpload1.SaveAs(path);
      Image1.ImageUrl = "./" + FileUpload1.PostedFile.FileName;


:)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900