Link to home
Start Free TrialLog in
Avatar of brian_appliedcpu
brian_appliedcpu

asked on

How to Set the Src Attribute of the Img Tag

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
ASKER CERTIFIED SOLUTION
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
hi
you can go as @carl_tawn comment
or simply create a folder under ur site and read the images from it
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
Avatar of brian_appliedcpu
brian_appliedcpu

ASKER

Use of a new virtual that points to the "external" path works, so I will use that. Thanks.