Hello everbody, I uploaded a image to server and want to show image on Image control by ASP. My code
String filename = FileUpload1.PostedFile.FileName;
string strFilename = Server.MapPath("Sample") + "//" + filename;
FileUpload1.PostedFile.SaveAs(strFilename);
//Show Image
Image2.ImageUrl=strFilename ;
But it does not run. Can you help me to show a image on server.Thanks
Loading
Dinesh BeniwalPosted Sep 14, 2011, 3:06 AM
If Satish's answer help you then Mark as accepted answer.
Thanks
toanhoi buiPosted Sep 14, 2011, 3:01 AM
Satish BhatPosted Sep 14, 2011, 2:17 AM
Try the following code.
String filename = FileUpload1.PostedFile.FileName;
string strFilename = Server.MapPath("Sample") + "\\" + filename;
FileUpload1.PostedFile.SaveAs(strFilename);
//Show Image
Image2.ImageUrl= "~/Sample/" + filename ;
// Here I am asuming that 'Sample' folder is directly under the application root. Otherwise change the path accordingly.