image url problems with subfolders

K

Keith G Hicks

I had the following on a page:

<asp:Image runat="server" ID="imgGradLarge" ImageUrl='<%# "ClassmatePics/" &
Eval("GradPhotoFileName") %>'></asp:Image>

The folder "ClassmatePics" was off my site's root. This was working fine.

Some people made recommendations to move folders like this (where users can
upload images) to the App_Data folder so I did that as follows:

C:\Inetpub\wwwroot\Website1\App_Data\ClassmatePics

Of cousre I changed all my code in the images to account for the change as
follows (sevearl ways shown below)

<asp:Image runat="server" ID="imgGradLarge" ImageUrl='<%#
"~/App_Data/ClassmatePics/" & Eval("GradPhotoFileName") %>'></asp:Image>

<asp:Image runat="server" ID="imgGradLarge" ImageUrl='<%#
"App_Data/ClassmatePics/" & Eval("GradPhotoFileName") %>'></asp:Image>

<asp:Image runat="server" ID="imgGradLarge" ImageUrl='<%#
"Website1/App_Data/ClassmatePics/" & Eval("GradPhotoFileName")
%>'></asp:Image>

<asp:Image runat="server" ID="imgGradLarge" ImageUrl='<%#
"/Website1/App_Data/ClassmatePics/" & Eval("GradPhotoFileName")
%>'></asp:Image>


None of the above work at all. No image shows up. The images are in the
folder they're supposed to be in. The folders have read privileges. I don't
get any errors. I just get blank images where before they showed up
correctly. The whole url path thing is goign to be the death of me. It
doesn't seem consistent. Not sure what to do here to get this right. Hope
someone can help.

Thanks,

Keith
 
K

Keith G Hicks

When I put an asp image control on a blank page and manually link it to one
of the images in the ClassmatePics folder in the design I can see the image
in design but if I run the app, it doesn't show up on the page (no errors,
just no picture). If I change it to a url of something that's in a folder
rigth off the root (like my Website1/images folder) it does show up in
runtime.

Keith
 
B

bruce barker

app_data is a protected folder, that users can not access directly. if your
users upload their images this is the correct folder, because any other would
force a recompile of the site (unless the image folder is in a different
vdir).

you just want an image display page. google this group for example code to
display an image with an aspx page (usually from a database, but filesystem
is the same).


-- bruce (sqlwork.com)
 
K

Keith G Hicks

I have no problem displaying images on an aspx page. That's easy. However,
every time I search for how to do it from the App_Data folder I get things
like this:
http://benfulton.net/blog/2005/11/no-images-allowed-in-appdata-folder.html &
http://forums.asp.net/p/1223850/2191284.aspx (quote from the 2nd link:
"First thing i observed is that you are storing your Image files under
App_Data folder which is not a good Idea.. App_Data folder can only be
contains data such as .mdf files and so on.")

I'm looking for either confirmation that this is true or some very specific
direction on how to make it work. If what I reference above IS true then I'm
looking for advice on where to put image folders. Is it ok to just have them
off the root? Should they be subfolders of the main images folder? Again,
I'm looking for specific examples and/or code and advice. Bottom line is
there seems to be conflicting info out there. Some of you say that uploads
need to go in App_Data because it won't force a recompile but most everyone
else confirms my problem that images CANNOT be dealt with by asp.net if they
are placed in the App_Data folder.

Keith
 
S

ShaneLM

I think Bruce was suggesting you create a page that serves the image
from the app_data folder. Since that folder is protected, you won't be
able to load your images by accessing it directly. But, if you create
a page that will load the image from the app_data folder, send the
correct headers to make it an image instead of a page, and then write
the image data out, it may work. For example "showImage.aspx?
image=hello.jpg" would be in your image tag.

If this is not what Bruce was suggesting, then forgive me - i'm a
newbie too.

It seems to me like it might be more hassle than convenience storing
the images there. Perhaps you should try a different folder and set up
permissions accordingly.

Good luck!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top