Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

FileSystemObject createTextFile and relative paths

135 views
Skip to first unread message

Sean

unread,
Apr 12, 2000, 3:00:00 AM4/12/00
to
I have the following in a directory. I would like to have it create a
file in the following relative location. ie. up one level.

Dim fso, MyFile
Set fso = server.CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.CreateTextFile("..\testfile.txt", True)
MyFile.WriteLine("This is a test.")
MyFile.Close

Thanks in advance,
Sean


Brian Andrus

unread,
Apr 12, 2000, 3:00:00 AM4/12/00
to
Use the server.mappath and strip it from there.

Brian
"Sean" <no...@here.now> wrote in message news:38F52DE7...@here.now...

mdc

unread,
Apr 13, 2000, 3:00:00 AM4/13/00
to
On Wed, 12 Apr 2000 19:16:07 -0700, Sean <no...@here.now> wrote:

>I have the following in a directory. I would like to have it create a
>file in the following relative location. ie. up one level.
>
>Dim fso, MyFile
> Set fso = server.CreateObject("Scripting.FileSystemObject")
> Set MyFile = fso.CreateTextFile("..\testfile.txt", True)
> MyFile.WriteLine("This is a test.")
> MyFile.Close

You have to use a full filesystem path, not a relative URL, in
the FileSystemObject. Use Server.MapPath to convert the
relative path to a full one.

mdc

--------------------------
http://www.mc2studios.com/

Sean

unread,
Apr 13, 2000, 3:00:00 AM4/13/00
to
When I use the below code with the complete path inserted, I get the
following error:

BEGIN ERROR
"c:\inetpu\wwwroot\a1\test.asp

Microsoft VBScript runtime error '800a0046'

Permission denied

a1\test.asp, line 16 "
END ERROR

line 16 is the CreateTextFile line, and test.asp is the asp file that has
this block of code in it.

My question is, am I doing something wrong in my code to produce this
error, or is it a permission problem on the webserver as the error implies?
The reason that I ask is the webserver is maintained by someone else, and
he thinks that it is a fault in my code.

Any help would be greatly appreciated,
Sean

Below is my modified code to include the complete path:

Dim fso, MyFile
Set fso = server.CreateObject("Scripting.FileSystemObject")

Set MyFile = fso.CreateTextFile("c:\inetpu\wwwroot\a1\testfile.txt", True)


MyFile.WriteLine("This is a test.")
MyFile.Close

The webserver is NT4, SP6 running IIS4 if that matters.

Bob Bell

unread,
Apr 13, 2000, 3:00:00 AM4/13/00
to
Does the account IUSR_<server> have write access to that
directory ??

Sean <no...@here.now> wrote in article <38F62C1F...@here.now>...

Sean

unread,
Apr 14, 2000, 3:00:00 AM4/14/00
to
Thanks much Bob. That is exactly what it was. I hate dealing with internal
bureaucracy!

Sean

0 new messages