Link to home
Start Free TrialLog in
Avatar of gbarje1
gbarje1

asked on

problem with grid view

i am using grid view for displaying images in my application.
i am creating a table to bind with grid view
it has two columns
1)image path
2)description of image
 
my problem is that images are not displayed if they are not from working directory
i mean
when i enter a row with path as "~/image.jpg" it is displayed
but when i enter path as"c:\images\image.jpg" it doesn't
So i cant figure out how to display images in grid view if they are not from my working directory
Avatar of myderrick
myderrick
Flag of Ghana image

This should do:

...\images\image.jpg

MD
path should be :
src="file:///c:/images/image.jpg"
Avatar of mahadevan_v
mahadevan_v

use server.mappath for getting appropriate directory and then display it.
Avatar of gbarje1

ASKER

all the above solutions are not working,
@ mahadevan i knw the path where i store the images.Also, for my application i am planning to store images on local drive and just their path in db.
i am writing my code in C#.
i have created an  asp grid view
i am creating the table in C# and binding it thru C# only.
my prob is if i put image in my working folder and then put ~ sign like "~\\image.jpg" the image is displayed but when i put the image in c: and put path as "c:\\image.jpg" the image is not displayed.
could u send a sample of ypur code
If this is a web application, there are three ways to set image URLs:
- full URL
- absolute path
- relative path

Full URL means a complete URL including the protocol, Fully Qualified Domain Name (FQDN) and the path to the image.  For example:
     http://www.mydomain.com/myapp/images/myimage.jpg

Absolute path is the directory and file path to the image from the root of the web application.  Absolute paths always start with a slash ("/"), which implies the root directory.  For example:
     /myapp/images/myimage.jpg

Relative path is the directory and file path relative to the path of the current web page.  Relative paths never start with a slash ("/"), and are resolved by the browser in relation to the current document.  For example, suppose you have the following directory structure:
    /myapp/images/
    /myapp/pages/
If you want to load an image from a page in the "/myapp" directory, you can do this:
    images/myimage.jpg
But if you want to load an image from a page in the "/myapp/pages" directory, you'll have to try this:
    ../images/myimage.jpg
(or use an absolute path from the root).

Notice that all this time I'm talking about URL paths, not physical paths in the web server.  This is because, ultimately, it will be the web browser who will ask for the images to the server, so it must have paths that it can understand.  The web browser has no idea of the physical file structure of your server, nor does it care; it only knows URLs.

Also, notice that for your web application to find an image, it needs to have access to it within its own directory structure.

     -dZ.
Avatar of gbarje1

ASKER

yes it is a web application but here the problem is the filesize of my images is quite big so i am not storing them on the server from where i am running the application but on NAS(Network access storage) Also,i am storing the path of the images (w.r.t network) in sql database and then want to load these images in my web application by entering this path stored in database . i hope u r getting what i am trying to say. my c# code is:-
Avatar of gbarje1

ASKER

sry forgot to attach code
here when i use ~ sign for r1["Image"] = "~\\Images\\Image.jpg"; images are displayed but wen i use
r1["Image"] = "E:\\web app\\Images\\Image.jpg"; images are not shown.



DataTable tab = new DataTable();
            DataColumn col1 = new DataColumn("Image", typeof(System.String));
            DataColumn col2 = new DataColumn("Description", typeof(System.String));
            tab.Columns.Add(col1);
            tab.Columns.Add(col2);
            DataRow r1 = tab.NewRow();
                   r1["Image"] = "~\\Images\\Image.jpg";
            r1["Description"] = "Test";
            tab.Rows.Add(r1);
 
            foreach (DataColumn col in tab.Columns)
           {
            System.Web.UI.WebControls.ImageField i1Field = new System.Web.UI.WebControls.ImageField();
               i1Field.HeaderText = tab.Columns[0].ColumnName;
           GridView1.Columns.Add(i1Field);
               System.Web.UI.WebControls.BoundField bField = new System.Web.UI.WebControls.BoundField();
               bField.DataField = tab.Columns[1].ColumnName;
               bField.HeaderText = tab.Columns[1].ColumnName;
               GridView1.Columns.Add(bField);
            }
            GridView1.DataSource = tab;
            //Bind the datatable with the GridView.
            GridView1.DataBind();

Open in new window

Avatar of gbarje1

ASKER

sry again following lines are commented:-
//foreach (DataColumn col in tab.Columns)
//{
the code between the brackets is not commented
//}
ASKER CERTIFIED SOLUTION
Avatar of DropZone
DropZone
Flag of United States of America 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
Here are more details on how to create a virtual directory in IIS:
       http://support.microsoft.com/kb/172138

       -dZ.
Avatar of gbarje1

ASKER

Thank you very much.....
problem solved with help of virtual directory......