views:

78

answers:

3

I want to show a collection of images in list view.

I have an image table in a MySQL database, the fields are photoId, PhotoName, ...

I want to bind the image control Url in the item template of the list view on the physical path (stored in config file) + photoName in the DB.

ImageUrl ='<%# ConfigurationManager.AppSettings.GetValues("ThePath").First() + 
    "\\" + "News Images" + "\\" + "Unit #" + Session["UserData"].ToString() + 
    "_" +"News #"+ NewsIdTextBox.Text + "\\"+Eval("photoName") %>' 

but it doesn't work, no photos appeared, only the photos names.

I tried to store the path in the database but it throws an exception.

A: 

I dont really understand what you are trying to do but if you trying to create a url, you need to start using forward slashes instead of back slashes and remove spaces from your path.

darthjit
i want to show set of images in a listview , so i tried to bind the ImageUrl to a specific path(physical path stored in config file and file name stored in data base) but i fail to do that
A: 

just-name, where do you store your images, in database or in the folder/filepath? Do your images exist in the ImageUrl filepath? The method you are using won't work if you want to retrieve images from database. The control will try to retrieve the images from the ImageUrl filepath, and (possibly) throw an exception when the image file does not exist.

Gan
the images are stored in folder out the server , tried to solve the problem::1- convert the path to relative path in config file <add key="ThePath" value="../../../NewsFiles"/>2- bind the image url ::ImageUrl = '<%# Container.DataItem %>'but in run time when trace my code :i find the image url = ../../../NewsFiles/NewsImages/UnitNum1_NewsNum5/back_button1.jpgand no images are appeared i don't know how to bind the path out of my server to the image url.
just-name, there are three "../" in the value for "ThePath", are you sure that is correct? Assume that your Newsfiles folder is in "http://<webroot>/Newsfiles/", Your ImageUrl will only successfully load the images out if the aspx page with the ImageUrl is three level deep in your website, i.e. "http://<webroot>/Level1/Level2/Level3/PageWithImage.aspx". Does this help you?
Gan
A: 

Image's url should point to web path because client loads it, not server, i.e. http://example.com/images/logo.png but not d:\www\example.com\images\logo.png because client's browser will try to load this images from user's computer while it doesn't exist of course. And encode resulting string, i.e. replace spaces with %20, so on.

Otherwise, if you want to create a path to load the image by server-side, it's ok.

abatishchev
the images are stored in folder out the server , tried to solve the problem::1- convert the path to relative path in config file <add key="ThePath" value="../../../NewsFiles"/>2- bind the image url ::ImageUrl = '<%# Container.DataItem %>'but in run time when trace my code :i find the image url = ../../../NewsFiles/NewsImages/UnitNum1_NewsNum5/back_button1.jpgand no images are appeared i don't know how to bind the path out of my server to the image url.
my images indeed in the previous path but i don't know why the photos doesn't appear
@just-name: are images (by ../../path) accessible from a browser? or only for server?
abatishchev
i don't understand u, but those images are uploaded out the server (every set of images for specific news has its folder which resides in the folder detected in the config file)
@just-name: btw, You can use ~ (tilde) to format code into comments. Could you please re-post your previous comment with formatting? And delete first after that
abatishchev
`Managers.Photo p = new Managers.Photo();``if (e.CommandName == "Select")``{` `string dirPath=``ConfigurationManager.AppSettings.GetValues("ThePath").First() + "/" + "NewsImages" + "/" + "UnitNum" + FK_UnitId.ToString() + "_" + "NewsNum" + newsId + "/";``DataTable dt = p.GetAllPhotos(int.Parse(newsId));``List<string> l = new List<string>(dt.Rows.Count);``for (int i = 0; i < dt.Rows.Count; i++) {``l.Add(dirPath + dt.Rows[i]["photoName"].ToString());``}` `lv_showImages.DataSource = l;``lv_showImages.DataBind();`
sorry i didn't know how to use format in StackOverFlow
@just-name: How does look like value in app.config? is it relative path or url?
abatishchev
no it is relative path`<add key="ThePath" value="../../../NewsFiles"/>`
@just-name: Ok, right. Is this path visible to a user in the same manner? `http://example.com/foo/bar/../../../NewFiles` ? What exactly does user see?
abatishchev
thank u all of u guys , i fix my problem ,, the solution to this problem is to use generic handler to write the image on the browser.i'm so glad to solve this problem it takes 3 days.