Search code examples
asp-classic

Using a UNC path with Classic ASP FileSystemObject


According to the websites I could find the below code should work. If I change the path to C:\whats_new.txt it works just fine.

Const Filename = "\\SCPAFS1PW\returns\whats_new.txt"    ' file to read
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0

' Create a filesystem object
Dim FSO
set FSO = server.createObject("Scripting.FileSystemObject")

' Map the logical path to the physical system path
Dim Filepath
Filepath = Filename

if FSO.FileExists(Filepath) Then <--This always returns false

Solution

  • The system reports the file does not exist. In fact it was actually a permissions issue. Microsoft designed the error so that if you do not have permission you cannot fish to figure out file names on a folder.

    I modified my permisions to the directory and I was able to access it using a UNC path.