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
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
path should be :
src="file:///c:/images/ima ge.jpg"
src="file:///c:/images/ima
use server.mappath for getting appropriate directory and then display it.
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.
@ 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.
- 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.
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:-
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.
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();
ASKER
sry again following lines are commented:-
//foreach (DataColumn col in tab.Columns)
//{
the code between the brackets is not commented
//}
//foreach (DataColumn col in tab.Columns)
//{
the code between the brackets is not commented
//}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Here are more details on how to create a virtual directory in IIS:
http://support.microsoft.com/kb/172138
-dZ.
http://support.microsoft.com/kb/172138
-dZ.
ASKER
Thank you very much.....
problem solved with help of virtual directory......
problem solved with help of virtual directory......
...\images\image.jpg
MD