How do I Use FileSystemObject?

T

TC

I'm trying to write some simple code using FSO, but I can't make it
work. There are a many FSO tutorials on the web, but they all start
with a line similar to:

set fs=Server.CreateObject("Scripting.FileSystemObject")

Yet that line simply doesn't work. I've tried it on my server and on
my development PC, both of which are configured as web servers running
ASP. I suspect that these computers simply aren't configured to
support FSO, but nowhere can I find any hint of how to do that
configuration. Can anyone help?

-TC
 
T

TC

Try this:

<% @Language="VBScript" %>
<%  Option Explicit
    Const cASP = "MapPath.asp"
    Dim strSMP
        strSMP = Server.MapPath(cASP)
    Response.Write "<li>" & strSMP
    Dim objFSO
    Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
    Response.Write "<li>" & objFSO.GetFile(strSMP).DateCreated
    Set objFSO = Nothing
%>

Call it via (or something like):http://localhost/MapPath.asp

Here's the output I got:

* C:\Inetpub\wwwroot\MapPath.asp
* 02/03/2008 10:44:19 PM

What do you get?

I get an "Invalid class string" error on line 8.
 
T

TC

Try this:
<% @Language="VBScript" %>
<% Option Explicit
Const cASP = "MapPath.asp"
Dim strSMP
strSMP = Server.MapPath(cASP)
Response.Write "<li>" & strSMP
Dim objFSO
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Response.Write "<li>" & objFSO.GetFile(strSMP).DateCreated
Set objFSO = Nothing
%>
Call it via (or something like):http://localhost/MapPath.asp
Here's the output I got:
* C:\Inetpub\wwwroot\MapPath.asp
* 02/03/2008 10:44:19 PM
What do you get?

I get an "Invalid class string" error on line 8.

What are you running?

What's your:
a)    O/S; (e.g. Windows XP Pro)?
b)    IIS version; (e.g. IIS 5.1)?
c)    Web server's physical root path; (e.g. C:\Inetpub\wwwroot\)

Does any ASP page work?

For example, save the following as "MapPath.asp" (like before);
what does it return?

<% @Language="VBScript" %>
<% Option Explicit
Const cASP = "MapPath.asp"
Response.Write "<li>" & Server.MapPath(cASP)
%>

A Google of "IIS FSO" (without the quotes) found:

[thelist] File System Object not working on IIS
URL:http://lists.evolt.org/archive/Week-of-Mon-20040726/162270.html

Problems with FileSystemObject
URL:http://www.thescripts.com/forum/thread53833.html

and others.- Hide quoted text -

- Show quoted text -

a) My operating system is Windows XP in one case, and Windows Server
2003 in the other.
b) I'm running IIS 5.1 and IIS 6.0.
c) The web server's physical root path is C:\Inetpub\wwwroot\ on both
computers.

I've seen the pages blaming antivirus script blocking, but I don't
think that's the problem in this case. My antivirus is NOD32. When I
completely disable it, I see no change. Also, I believe that if script
blocking was the problem, I would get an error when I try to use FSO,
not when I try to initialize it. In other words, I would expect to
hang on line 9, not receive an error on line 8, in the sample code
above.

In every test so far, I always fail on the line which includes
Server.CreateObject("Scripting.FileSystemObject"). This leads me to
ask, What are the prerequisites for using the FileSystemObject? Is it
supposed to be automatically enabled on any computer running IIS?

-TC
 
T

TC

"TC" <[email protected]> wrote in message
I get an "Invalid class string" error on line 8.
What are you running?
What's your:
a)    O/S; (e.g. Windows XP Pro)?
b)    IIS version; (e.g. IIS 5.1)?
c)    Web server's physical root path; (e.g. C:\Inetpub\wwwroot\)
Does any ASP page work?
For example, save the following as "MapPath.asp" (like before);
what does it return?
<% @Language="VBScript" %>
<% Option Explicit
Const cASP = "MapPath.asp"
Response.Write "<li>" & Server.MapPath(cASP)
%>
A Google of "IIS FSO" (without the quotes) found:
[thelist] File System Object not working on IIS
URL:http://lists.evolt.org/archive/Week-of-Mon-20040726/162270.html
and others.- Hide quoted text -
- Show quoted text -

a) My operating system is Windows XP in one case, and Windows Server
2003 in the other.
b) I'm running IIS 5.1 and IIS 6.0.
c) The web server's physical root path is C:\Inetpub\wwwroot\ on both
computers.

I've seen the pages blaming antivirus script blocking, but I don't
think that's the problem in this case. My antivirus is NOD32. When I
completely disable it, I see no change. Also, I believe that if script
blocking was the problem, I would get an error when I try to use FSO,
not when I try to initialize it. In other words, I would expect to
hang on line 9, not receive an error on line 8, in the sample code
above.

In every test so far, I always fail on the line which includes
Server.CreateObject("Scripting.FileSystemObject"). This leads me to
ask, What are the prerequisites for using the FileSystemObject? Is it
supposed to be automatically enabled on any computer running IIS?

-TC- Hide quoted text -

- Show quoted text -

I found the problem. Apparently, something changed my registry
permissions. I went into the registry and corrected the permissions.
Now FSO works. The bug is described in the following usenet articles:

http://groups.google.com/group/microsoft.public.inetserver.iis/browse_thread/thread/aa4f80933182a5a2
http://groups.google.com/group/micr...general/browse_thread/thread/98a8a12f6a2eb055

-TC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top