Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to Set the Src Attribute of the Img Tag

Posted on 2011-02-12
4
Medium Priority
?
1,187 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
[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
4 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 2000 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

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
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 …

598 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