Annatar
Annatar

Reputation: 381

VBScript (Classic ASP): Trying to output Absolute Path of Current Dir to Browser, but getting Error

I'm trying to print to the browser screen the Absolute Path of the current directory using Classic ASP. (equivalent to PHP's echo command).

I'm getting this error on the last line of the code below: "Microsoft VBScript runtime error '800a01a8' Object required: 'Document' /Research/ro.asp, line 17"

I've tried a couple different methods to print to the screen (Like WScript.StdOut.Write) and they return the same error as well.

I suspect that my error has something to do with the fact that it is an object, and objects require a different method of printing to the screen.

Any thoughts on this from anyone?

samplefile.asp=

<%

Dim szCurrentRoot: szCurrentRoot= ""

'Create the File System Ojbect
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

'Get the Absolute Path of the current directory
szCurrentRoot = objFSO.GetParentFolderName(Server.MapPath(Request.ServerVariables("URL")))

'Print to the screen.  The following line is line 17 which causes the error
Document.Write(szCurrentRoot)
%>

After some more research, I found the answer to my question:

Response.Write(szCurrentRoot)

This way of writing to the browser screen was successful.

Upvotes: 2

Views: 7616

Answers (3)

Rodrigo
Rodrigo

Reputation: 4395

<%

Dim szCurrentRoot: szCurrentRoot= ""

'Create the File System Ojbect
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

'Get the Absolute Path of the current directory
szCurrentRoot = objFSO.GetParentFolderName(Server.MapPath(Request.ServerVariables("URL")))

'Print to the screen.
Response.Write szCurrentRoot
%>

Response.Write is the way to send text data back to the client. Use <% %> is a shortcut to this method.

Upvotes: 5

Neil
Neil

Reputation: 55392

You can't print to the screen from ASP, you can only write a response back to the browser, using Response.Write Server.EncodeHTML(szCurrentRoot) or the shorthand <%=Server.EncodeHTML(szCurrentRoot) %> if you are not inside a code block.

Upvotes: 1

Nathan Romano
Nathan Romano

Reputation: 7096

Yea Document is not implicitly defined if you are running this from the command line

eg.

cscript whatever.vbs

If you were to run this script inside of IE in a you would have access to "document"

Try doing this

Set ie = CreateObject(“InternetExplorer.Application”) ie.document.write(szCurrentRoot)

Upvotes: -1

Related Questions