Search code examples
vbscriptasp-classicfilesystemobject

ASP Creating Text File ObjFileSys.CreateTextFile


I am trying to create a textfile in a temp directory...

I don't understand what I am doing wrong...

My Error is:

Microsoft VBScript runtime error '800a004c'
Path not found
/racklabels/desktop/printLabel.asp, line 128

There is a temp directory on my server I am running this from...

strFileNameQAD = "C:\temp\" & strFileNameRBB

'Create the files, write to them & close them.
If bBackFlush = True Then
    Set filQAD = objFileSys.CreateTextFile(strFileNameQAD)
    filQAD.WriteLine ("H::" & strPart & strLocation & strSite & strQty & strSerial & strRef & strUserID & strAccount & strSubAccount & strCostCenter & strEffDate & strYes)
    filQAD.WriteLine ("D::" & strFromLocation & strNo & strUserID)
    filQAD.Close
    Set filQAD = Nothing
End If

Solution

  • The FileSystemObject is complaining about the path contained in the strFileNameQAD, try placing a Response.Write strFileNameQAD : Response.Flush before the offending line to see what strFileNameQAD outputs as.

    Note: Response.Flush causes the server to write the response headers and buffer, so even if your script errors the output will be shown first.

    strFileNameQAD = "C:\temp\" & strFileNameRBB
    
    'Create the files, write to them & close them.
    If bBackFlush = True Then
        'Output strFileNameQAD variable to check content
        Response.Write strFileNameQAD : Response.Flush
        Set filQAD = objFileSys.CreateTextFile(strFileNameQAD)
        filQAD.WriteLine ("H::" & strPart & strLocation & strSite & strQty & strSerial & strRef & strUserID & strAccount & strSubAccount & strCostCenter & strEffDate & strYes)
        filQAD.WriteLine ("D::" & strFromLocation & strNo & strUserID)
        filQAD.Close
        Set filQAD = Nothing
    End If
    

    Does the strFileNameQAD variable contain the expected path? My guess would be that strFileNameRBB is empty so the FileSystemObject sees C:\temp\ but no file to create, hence the error.