Click here to Skip to main content
15,893,663 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello Friends,

Can anybody tell me hoe to display an image at runtime in ASP.NET?
I have provided the full path of the image but stil it doesnt seem to work. I have provided my code snippet below.Can any one of you help me in this?

C#
if (strques.Contains(@"\"))
       {
           lbl_ques.Visible = false;
           Image1.Visible = true;
           Image1.ID = "image" + intcount;
           Image1.ImageUrl = strques;
       }


whre strques contains the path of the image that is
MSIL
E:\Swapnil\TestUSS22-1-2010

\QuizWebApp\Images\image_PuzzleMagicSQ\PuzzleMagicImgQuiz1-Q1.jpeg


which changes at runtime to give another puzzle.
Posted

As CG said earlier you should not use physical path, Remove Server.MapPath as it is giving the physical path.
Give path in this format:

Image1.ImageUrl = "~/Folder1/Folder2/image.jpg";

here ~ will point to root folder of your application.
 
Share this answer
 
You should provide only paths that exist within your web server, and you should use paths relative to the server root.
 
Share this answer
 
Yes My path exists with my web browser..The puzzle images are stored in the image_PuzzleMagicSQ folder.
 
Share this answer
 
v2
code is below
Image1.ImageUrl = Server.MapPath(@"\image_PuzzleMagicSQ\picture1.jpg")
based on your image location you should change the path.
 
Share this answer
 
v2
Nop.That doesnt work it seems. I am getting an exception as in HttpException is unhandled by the user code.
 
Share this answer
 
Thanks Jaams..
It seems to work now. U got it absolutly right.
I was using the physical path. Now I chaged it and now its working fine.
 
Share this answer
 

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