• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2038
  • Last Modified:

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


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?

1 Solution
Hi mnamiri,

That's the way MapPath works, you can do something like:

Set rootFolder = fso.GetFolder(Replace(Server.MapPath("images/thumbnails"),Server.MapPath("/"),""))

To strip out the real root part.

Tim Cottee
mnamiriAuthor Commented:
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:


Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now