Server.Mappath
-
Hi. in my web application there is a option for showing the photos,when click photos button will load photos.aspx page and am keeping the images in the server folder name Photos.in my local machine while loading the page i will get all the images which i store in the Photos folder,but i host this page and open this page am not getting any images.the page load event as follows.what is wrong with this code.somebody can help me. if (!IsPostBack) { DataSet ds = new DataSet(); DataTable dt = new DataTable("Photos"); dt.Columns.Add("Photos", Type.GetType("System.String")); foreach (string Files in Directory.GetFiles(Server.MapPath("Photos"), "*.jpg")) { dt.Rows.Add(Files); } ds.Tables.Add(dt); this.dgPhotos.DataSource = ds; this.dgPhotos.DataBind(); }
-
Hi. in my web application there is a option for showing the photos,when click photos button will load photos.aspx page and am keeping the images in the server folder name Photos.in my local machine while loading the page i will get all the images which i store in the Photos folder,but i host this page and open this page am not getting any images.the page load event as follows.what is wrong with this code.somebody can help me. if (!IsPostBack) { DataSet ds = new DataSet(); DataTable dt = new DataTable("Photos"); dt.Columns.Add("Photos", Type.GetType("System.String")); foreach (string Files in Directory.GetFiles(Server.MapPath("Photos"), "*.jpg")) { dt.Rows.Add(Files); } ds.Tables.Add(dt); this.dgPhotos.DataSource = ds; this.dgPhotos.DataBind(); }
Sounds like a permissions problem. Do you have view permissions to the root of the drive you are trying to view? Another option is to use classic asp style of debugging and output any errors, or even the path of the photos folder.
Darroll
-
Hi. in my web application there is a option for showing the photos,when click photos button will load photos.aspx page and am keeping the images in the server folder name Photos.in my local machine while loading the page i will get all the images which i store in the Photos folder,but i host this page and open this page am not getting any images.the page load event as follows.what is wrong with this code.somebody can help me. if (!IsPostBack) { DataSet ds = new DataSet(); DataTable dt = new DataTable("Photos"); dt.Columns.Add("Photos", Type.GetType("System.String")); foreach (string Files in Directory.GetFiles(Server.MapPath("Photos"), "*.jpg")) { dt.Rows.Add(Files); } ds.Tables.Add(dt); this.dgPhotos.DataSource = ds; this.dgPhotos.DataBind(); }
The Directory.GetFiles returns an array of physical file paths on the server. As long as the server is the same computer as the client computer, you will be able to see the images, as you see the images that are stored locally on your computer, as they happen to have the exact same file path as the images that are stored on the server, as they happen to be the exact same files. When you view the page on the hosted server, the images are only stored on the server, so when you try to view the images they are not there, as you no longer have a local copy of the images on your computer with the same file paths as on the server. You have to make sure that you use the virtual path to each image, not the physical path, when you put them on the page.
--- single minded; short sighted; long gone;