Click here to Skip to main content
15,911,896 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a fileupload and a button control button on my webform(asp.net 2010).

What i want is , as soon as i click on the button to upload the file(image), it should dynamically create an image control and set the imageurl to be the one which i just uploaded. And the image should be displayed...however , it is not working..please help me giving a reason..Following si the code :-
protected void Button1_Click(object sender, EventArgs e)
    {
string str=FileUpload1.FileName;
    string path=Server.MapPath("image");
        string fulpath=path + "\\" + str;
        FileUpload1.PostedFile.SaveAs(fulpath);
        Image img = new Image();
        Page.Form.Controls.Add(img);
        img.ImageUrl = Server.MapPath(str);
    }
Posted
Updated 3-Aug-11 23:43pm
v2

1 solution

May be Server.MapPath(str) is not getting the correct path. So, try this.
img.ImageUrl = fulpath;

or
img.ImageUrl = FileUpload1.PostedFile;
 
Share this answer
 
Comments
shikhar gilhotra 4-Aug-11 7:12am    
not working...

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