?
Solved

Dynamic image not appearing in online assessment

Posted on 2008-06-23
13
Medium Priority
?
458 Views
Last Modified: 2013-11-07
Hi all,

The attached code is a segment from my online assessment web page. This code used to work, but as of today it has stopped. I do not know when it last worked. All the other assessment question work fine, but if the question is an image, the image does not show, I only get the image placeholder. I have tested this in Firefox and IE and the result is the same, the 'test' string variable is where I have tested to see if the path is correct, which it is and the image exists. I just cannot see why it has stopped working.

Can you think of anything else that could be stopping ut showing?

Cheers.
If row("questiontype") = 37 Then
                    Dim img As Image = New Image()
                    Dim test As String = Server.MapPath("~/secure/images/aqimages/" & row("questionImageFilename").ToString)
                    img.ImageUrl = Server.MapPath("~/secure/images/aqimages/" & row("questionImageFilename").ToString)
                    img.Width = 700
                    img.Height = 300
                    img.Visible = True
                    pnlAssessment.Controls.Add(img)
                End If

Open in new window

0
Comment
Question by:G0ggy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
  • 2
13 Comments
 
LVL 5

Expert Comment

by:cwickens
ID: 21845422
Have you run the site in debug mode with a breakpoint here to make sure that you are hitting the function?

If it worked previously with no issues then you may not be passing the right value in or the data in your DB may not be accurate.
0
 
LVL 11

Author Comment

by:G0ggy
ID: 21845435
It hits the function and the value of 'test' in the code is the correct path to the image (tested by copying it into IE, the image displays correctly)
0
 
LVL 5

Expert Comment

by:cwickens
ID: 21845495
Have you tried removing the "~" from the Server.MapPath?  I think that is redundant.
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 11

Author Comment

by:G0ggy
ID: 21845639
That doesn't make any difference. It's wierd, if you look at this section of a screenshot, you can see the image place-holder, which is not broken (which would indicate that the image could not be found) yet it does not appear...
Untitled-1.gif
0
 
LVL 33

Expert Comment

by:raterus
ID: 21845727
I doubt it would load the page if it wasn't, but are you SURE you are adding a

System.Web.UI.WebControls.Image
and not a
System.Drawing.Image ?

Does it work if you use an HtmlImage control?

0
 
LVL 11

Author Comment

by:G0ggy
ID: 21846219
Same results as before, tried both of your suggestions...
0
 
LVL 33

Accepted Solution

by:
raterus earned 1500 total points
ID: 21846251
Why are you using Server.MapPath here?  That turns a URL into a local path to the server.  So the browser is seeing something like this

<img src="c:\inetpub\wwwroot\images\someimage.gif" />

Is this what you want?
0
 
LVL 11

Author Comment

by:G0ggy
ID: 21846304
The image is stored locally yes...
0
 
LVL 33

Expert Comment

by:raterus
ID: 21846324
locally on the users computer, right?

Regardless, this isn't an ideal solution, and browsers are cracking down on any access a web page can have to the users hard drive.  If it suddenly stopped working, I would start looking into security settings in the browser, because your code is probably fine.
0
 
LVL 11

Author Comment

by:G0ggy
ID: 21846379
No locally on the web server. If I spec the situation for you. The instructors can create questions, which can be multiple choice, text or images. If it is an image question they upload an image file to the web server. I need to reference this image file from the question in the database. The name of the image is stored with the question.

Your previous comment made me suspicious about the paths, so I changed the URL to a fully qualified http address to the localhost which worked. Is this the ideal solution?
0
 
LVL 33

Expert Comment

by:raterus
ID: 21846409
Certainly yes.  You really shouldn't EVER have to use a local path within a "web"page.  If the resource isn't being served over HTTP, then there isn't much of a guarantee your user is ever going to see them.
0
 
LVL 11

Author Comment

by:G0ggy
ID: 21846451
Then the points are yours my good man.
0
 
LVL 11

Author Closing Comment

by:G0ggy
ID: 31469684
Cheers.
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question