Solved

How to Set the Src Attribute of the Img Tag

Posted on 2011-02-12
4
1,162 Views
Last Modified: 2012-05-11
I have an ASP.NET page that, when viewed, defines an HMTL table with a row, plus cells within the table row using code like the following:

        HtmlTable tbl = new HtmlTable()
        HtmlTableRow tblRow = new HtmlTableRow()
        HtmlTableCell tblCell = new HtmlTableCell()

        Page.Controls.Add(tbl)

The page dynamcally fills the HTML table with 10 images (Photo1.jpg, Photo2.jpg, Photo3.jpg, …, Photo10.jpg) that are stored in a subfolder, (the Images subfolder) under the website’s root folder. The physical path is similar to C:\Inetpub\wwwroot\mysite\images and the InTRAnet site is browsed using a URL like http://Myserver/mysite/mypage.aspx. The ASP.NET page contains a For...Next loop like the following, which populates the HTML table:

    For I = 1 to 10
        tblCell.InnerHtml = "<img src='/Images/Photo" & CStr(I) & ".jpg' />"
        tblRow.Cells.Add(tblCell)
    Next I

This works fine and the HTML table properly displays all 10 images. The path assigned to the src attribute is, of course, the relative path, and I could have used the full path of <img scr=’http://myserver/mysite/images/photo1.jpg’ />, etc., and the page would have rendered the images as well.

The problem I am having is that a new “Pictures” folder has been introduced on the same IIS machine, but outside of the website. Its path is similar to C:\Photos\Pictures. Therefore, using the same full or relative path like that above does not work, since the Pictures folder “lives” outside of the website. So I have tried assigning paths like the following to the src attribute, but without success:

    tblCell.InnerHtml = "<img src='file://C:/Photos/Pictures/Photo" & CStr(I) & ".jpg' />"
or
    tblCell.InnerHtml = "<img src='C:\Photos\Pictures\Photo" & CStr(I) & ".jpg' />"

And I even tried including the literal filename, such as:

    tblCell.InnerHtml = "<img src='C:\Photos\Pictures\Photo1.jpg' />"

I have tried so many combinations like those above that I have lost track. The result is either thumbnails or a red X that is displayed in each cell of the HTML table, instead of displaying actual photos.

I initially thought that the problem  was that maybe the page was processing client-side, instead of server-side, and therefore on the client machine, there would be no such path as C:\Photos\Pictures. But you get the same results (red X or thumbnails) when you browse the ASP page while sitting directly at the IIS machine.

To ensure that it wasn’t a permissions issue, I temporarily assigned to folder C:\Photos\Pictures the permissions of Read & Execute, List Folders, and Read, and these were assigned to group Everyone. That should give IUser (literally all users) sufficient access to the path, but the page still would not display the photos.

Any suggestions on how I can resolve this problem? Unfortunately, moving the Pictures folder inside of the website is not an option.

Thanks
0
Comment
Question by:brian_appliedcpu
4 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 34880694
You don't need to physically move the folder underneath your site, but you do need to create a virtual directory to it. The path to the file needs to be relative to your site and cannot directly access a path outside of your site.
0
 
LVL 16

Expert Comment

by:Kamal Khaleefa
ID: 34881387
hi
you can go as @carl_tawn comment
or simply create a folder under ur site and read the images from it
0
 
LVL 11

Expert Comment

by:G_H
ID: 34882156
The best option is a virtual directory. But, just so that you understand what is going on, and why it is failing when you use...

src="C:\pictures...

It is the client machine looking at it's own C drive.

I believe you can use this method, if you use a UNC path to the image file.

GH
0
 
LVL 2

Author Closing Comment

by:brian_appliedcpu
ID: 34882577
Use of a new virtual that points to the "external" path works, so I will use that. Thanks.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
Lync server 2013 Backup Service Error ID 4049 – After File Share Migration
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

705 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now