Link to home
Start Free TrialLog in
Avatar of mnamiri
mnamiri

asked on

fso.GetFolder(Server.MapPath()) returns full path, not relative path to image

Hi,

I am using rootFolder to get the path for images in a directory which i am displaying via ASP.

Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set rootFolder = fso.GetFolder(Server.MapPath("images/thumbails/")) ' Here point to you folder.

Unfortunatley, i only just noticed that rootFolder returns the full path on the server. i.e. C:\inetsrv\wwwroot\website1\images\thumbnails\
as opposed to a relative path to the asp page: \images\thumbnails

this results in lots of broken links when i load the page up in a browser a machine other than the server, because all the images are pointing to the whole C:\ path not the relative path for the images on the server.

Is there any clean way i can fix this?

thanks
ASKER CERTIFIED SOLUTION
Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mnamiri
mnamiri

ASKER

I ended up doing the following as your code raises a couple errors.

RelativePath =   Replace(fso.GetFolder(Server.MapPath("images/employees/")),fso.GetFolder(Server.MapPath("/")),"")

and then just using the relative path wherever i need to...

FileSystemObject is a red herring here. You would be better off looking at the Request.ServerVariables collection to map ropor relative paths. Good article here:

http://www.4guysfromrolla.com/webtech/121799-1.shtml