I have developed a Sales appliation..There are images of the products which I want to display .
My Issue
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.
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 outsidethe
root directory where my application is stored,but in the same computer ....Here is my doubt whethere server.mappath will work or not ?.
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.
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"
Else
img.Visible = False
End If
End If
Next
End Sub
Always return false.But the code will display images correctly If I remove the checking of file existance.
ashrafnrk
Member
6 Points
24 Posts
Storing Image files in Web Application
Dec 27, 2012 01:25 PM|LINK
Hi All
I have developed a Sales appliation..There are images of the products which I want to display .
My Issue
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.
Thanks
RichardY
Star
8376 Points
1573 Posts
Re: Storing Image files in Web Application
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.
ajaya_rout
Member
156 Points
47 Posts
Re: Storing Image files in Web Application
Dec 27, 2012 01:52 PM|LINK
Try this
string ur_path="";
string Path="";
Path=Server.MapPath(path);
if(System.IO.File.Exists(path)){
//do your code
//like System.IO.File.delete(Path);
}
If Any issue post some of ur code snippet to verify.
Thanks
ashrafnrk
Member
6 Points
24 Posts
Re: Storing Image files in Web Application
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 ?.
geniusvishal
Star
14190 Points
2796 Posts
Re: Storing Image files in Web Application
Dec 28, 2012 10:34 AM|LINK
Have you used Server.MapPath with the path variable??
http://msdn.microsoft.com/en-us/library/ms178116.aspx
My Website
www.dotnetvishal.com
Sujeet Saste
Contributor
3008 Points
572 Posts
Re: Storing Image files in Web Application
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.
Do FEAR (Face Everything And Rise)
Please mark as Answer if my post helps you..!
My Blog
ashrafnrk
Member
6 Points
24 Posts
Re: Storing Image files in Web Application
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.
Sujeet Saste
Contributor
3008 Points
572 Posts
Re: Storing Image files in Web Application
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.
Do FEAR (Face Everything And Rise)
Please mark as Answer if my post helps you..!
My Blog
ashrafnrk
Member
6 Points
24 Posts
Re: Storing Image files in Web Application
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" Else img.Visible = False End If End If Next End SubAlways return false.But the code will display images correctly If I remove the checking of file existance.
RichardY
Star
8376 Points
1573 Posts
Re: Storing Image files in Web Application
Dec 29, 2012 06:57 PM|LINK
You cannot use http paths in File.Exists(). It supports network shares and local file system.