Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Dec 30, 2012 05:24 AM by mudassarkhan
Dec 27, 2012 01:25 PM|LINK
I have developed a Sales appliation..There are images of the products which I want to display .
If I keep images inside my application folder it is fine.But I want to keep it in a directory outside the application but in the same server.This is becuase some other application also want to load the images
from the same source directory.I created a virtual directory for the images folder situated outside the application and I was able to display the images in my application.But I was not able to check the existance of file....I used the system.io.fileexists
command but it always returned false.
Any help on this issue will be highly appreciated.
Dec 27, 2012 01:36 PM|LINK
The method is System.IO.File.Exists(path)
Make sure you are composing the path correctly. If you are still having issues, then post the relevant code.
Dec 27, 2012 01:52 PM|LINK
//do your code
If Any issue post some of ur code snippet to verify.
Dec 28, 2012 10:26 AM|LINK
System.Web.HttpException: 'http://10.0.0.26:8080/images/001A.jpg' is not a valid virtual path.
This is the error message I am getting.
'images' is a virtual directory..It maps to a directory 'images' which is located outside the
root directory where my application is stored,but in the same computer ....Here is my doubt whethere server.mappath will work or not ?.
Dec 28, 2012 10:34 AM|LINK
Have you used Server.MapPath with the path variable??
Dec 28, 2012 10:36 AM|LINK
I don't think, Server.MapPath will not work here, because you are trying to access Folder placed outside of your application.
Try by using actual path e.g. "http://www.yoursite.com/virtualdir/img.jpg"
Hope it helps.
Dec 29, 2012 06:34 AM|LINK
Strange thing is that I am able to display images from virtual directory but can't check whethere file exists or not...But I can check whether the file exists or not using physical path but can't display it using it.
Dec 29, 2012 07:37 AM|LINK
Can you post your code where you are showing images, I just want to check it, may be we find some cause there.
Dec 29, 2012 01:26 PM|LINK
Protected Sub LoadImages()
Session("imgpath") = "http://" & Request.Url.Host.ToString & ":" & Request.Url.Port.ToString & "/images/"
Dim rows As GridViewRowCollection
rows = GridView1.Rows
For Each row In rows
If row.RowType = DataControlRowType.DataRow Then
Dim ItemCode As String = GridView1.DataKeys(row.RowIndex).Values(0)
Dim imageurl As String = Session("imgpath") & ItemCode & "TH.jpg"
Dim img As ImageButton
img = CType(row.FindControl("btnImg"), ImageButton)
If System.IO.File.Exists(imageurl) Then
img.Visible = True
img.ImageUrl = Session("imgpath") & ItemCode & "TH.jpg"
img.Visible = False
Always return false.But the code will display images correctly If I remove the checking of file existance.
Dec 29, 2012 06:57 PM|LINK
You cannot use http paths in File.Exists(). It supports network shares and local file system.