MapPath to root folder RRS feed

  • Question

  • User-916682894 posted

     Hi Chaps,

    This is my first post on the .Net Forums - I hope I don't break any rules in the first post,

    I'm trying to make a VB based .Net page return a file to the user from a location external to the website.

    The file itself is a software setup that needs to site outside the Web Directory, basically, the page needs to pick up this file and send it to the user when the page is loaded, I've done some research into the problem and it does seem that ASP .Net will not be able to let the user download files from outside the WebDirectory (in this case, WWWROOT).

    Does anyone know if this can be done? I've pasted the code I'm playying about with below - but, I wouldn't be suprised if this is completely wrong

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

    Dim FilePath As String

    FilePath = Server.MapPath("..\setup.exe")

    Response.WriteFile(FilePath)End Sub


    Thanks in Advance




    Tuesday, September 22, 2009 10:08 AM


  • User-952121411 posted

     Hello, and welcome to the forums! Laughing

    I will try to help get you started with some help.  The 'Server.MapPath' method is the proper way to go about resolving the relative or virtual path on the server to your file.  The problem may exist with your 'dot-dot' ("..\setup.exe") notation which is used to indicate parent paths.  By default ParentPaths are disabled in IIS; read as follows:

    "For security reasons, the AspEnableParentPaths property has a default value set to FALSE. Scripts will not have access to the physical directory structure unless AspEnableParentPaths is set to TRUE."

    Server.MapPath Method:


    ...here is some more information about the ParentPaths setting in IIS6:



    What you may want to try instead is either of the following:

    'The ~ will get you to the root directory for the project you are currently in.  
    'If you need to drill down further make sure to indicates so like ("~/MyFiles/setup.exe")
    FilePath = Server.MapPath("~/setup.exe")
    '....or try this; gets the physical path to the root of the domain name
    FilePath = Server.MapPath("/setup.exe")

    Read these, they have great information as well:




    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 22, 2009 11:12 AM