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

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
0
mnamiri
Asked:
mnamiri
1 Solution
 
TimCotteeCommented:
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
0
 
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...

0
 
SThorogoodCommented:
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
0

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