Search code examples
asp-classiciis-7.5virtual-directoryfilesystemobject

Create Virtual Directory IIS7 to be use in GetFolder in Server.CreateObject("Scripting.FileSystemObject")


I am trying to create a virtual directory at my IIS7 and then use the virtual directory in the following code

sPath = "\CMapped\database\attendanceData\"

sDir = Server.MapPath(".") & sPath
    
response.write sDir

Set fso = Server.CreateObject("Scripting.FileSystemObject") 
Set obj_FolderBase = fso.GetFolder(sDir)
    
response.end

But I got the following error:

error

What I have done is as follow:

  1. I created the virtual directory and set the path to C:\ Drive. My localhost is at D:\ drive. I have also set Connect as and entered my log in and password. I am the administrator of the PC. Everything authorized.

    Authorized

  2. Then I go to C: and set it as a shared folder

    Shared

  3. I went back to IIS and click on the virtual directory -> Managed Virtual Directory -> Browse. I successfully connect to the directory

Success

Now when I try the code, everything failed. The GetFolder function doesn't seems to recognize the path. The web server is at D: and the file server is at C: Please help.

sPath = "\CMapped\database\attendanceData\"

sDir = Server.MapPath(".") & sPath
    
response.write sDir

Set fso = Server.CreateObject("Scripting.FileSystemObject") 
Set obj_FolderBase = fso.GetFolder(sDir)
    
response.end

The directory structure

DirectoryStructure


Solution

  • What you are trying would work in an href or src attribute, or with

    <!--#include virtual="\CMapped\database\attendanceData\yourfile.asp"-->.

    With server.mappath though I think you need to use the physical directory structure on the machine. As your virtual directory is on a different drive I suggest you go with

    sDir = "C:\full_physical_path_to\database\attendanceData\"