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

Posted on 2005-04-18
Last Modified: 2008-01-09

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?

Question by:mnamiri
    LVL 44

    Accepted 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

    Author Comment

    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...

    LVL 2

    Expert Comment

    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

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
    Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now