Reputation: 1209
What i Want to Do!
I want to show an image using image control. The source image is on file directory. The location of file is C:// directory while my project (Virtual Directory) is on D://. I want to set image source at page load.
What i have Done!
Following is the code I've written
Dim urls As List(Of String) = TryCast(Session("SliderUrls"), List(Of String))
Dim url As String = urls.Item(4)
Image1.ImageUrl = url
Note
url value is assigned properly. There no issue in url. On internet at some websites I've read that asp.net don't allow us to access resources outside virtual directory. So do you think that this may be the problem that i'm facing? and if so then how can i generate url for another virtual directory. Like i have a virtual directory on D://myproject and another virtual directory C://files. How can i generate url for Virtual directory on C://file while working in project which is in Virtual Directory D://myprojec.
Upvotes: 0
Views: 504
Reputation: 17680
The urls / paths have to be virtual and not physical.
Even though you've made the directory virtual, you appear to be trying to use the physical path instead.
Trying to use the physical path (C:/path) will not work.
Try using the base url of the other virtual directory and build your url from that.
For instance if the virtual directory is http://localhost/media
use that as the base url and attach the resources from there http://localhost/media/image.jpg
Dim baseUrl as String = "http://localhost/files"
Image1.ImageUrl = baseUrl + "/" + System.IO.Path.GetFileName(urls.Item(4))
I'm assuming the urls contains only the filenames (image.jpg
for instance)
you can also store the baseUrl in web.config
appSettings
Upvotes: 2