Create a file with FileSystemObject

J

jessie

This my code for practice:

<html>
<body>
<%
Response.Write("6 ")
dim fs,fname
set fs=CreateObject("Scripting.FileSystemObject")
set fname=fs.CreateTextFile("f:\test.txt")
fname.WriteLine("Hello World!")
fname.Close
set fname=nothing
set fs=nothing
%>
</body>
</html>

but I couldn't create the text file at all with no error warning.
How can I do this?

Thanks a lot.
 
M

Michael G. Schneider

jessie said:
This my code for practice:

snipped

but I couldn't create the text file at all with no error warning.
How can I do this?

What does the error message say?

The CreateTextFile might fail, because the file already exists (and the
overwrite parameter is not given). Or the CreateTextFile might fail, because
the account does not have enough access rights to the directory.

Michael G. Schneider
 
J

jessie

What does the error message say?

The CreateTextFile might fail, because the file already exists (and
the overwrite parameter is not given). Or the CreateTextFile might
fail, because the account does not have enough access rights to the
directory.


There is no error message. It is running and nothing comes out.
the overwrite parameter is ture for default, isn't it?
How to give it the right to access to the directory?
Thanks.
 
R

Rob Meade

...
There is no error message.

You could always try putting some

Response.Write "I got to this step"
Response.Write "Now I am at this step"

etc etc, to see where it gets to before it fails.

You could also check your browser settings to see if you have friendly
errors turned on (if so try turning it off).
the overwrite parameter is ture for default, isn't it?

I believe so, yes.
How to give it the right to access to the directory?

Browse through to the directory you are trying to save the file in,
right-click on it, left-click on properties.
Left-click the security tab, see if the 'IUSR_<computer_name>' account is
listed, if not - try adding it and give it everything but full access (or
give it full access but just for now to test etc).

Now rerun your code - you might want to stick a response.write at the end of
your code to so that you know if its got that far...

Just one question - you showed the F drive above - this will sound daft -
but its not your CD rom drive is it?

Regards

Rob
 
M

Michael G. Schneider

jessie said:
There is no error message. It is running and nothing comes out.
the overwrite parameter is ture for default, isn't it?
How to give it the right to access to the directory?

You should look up the CreateTextFile method. I believe, the overwrite is
False by default. The ASP page will be executed under a certain account. If
you do nothing special, this should be the IIS_machine account. This account
needs the access rights to the directory on the IIS Server. For setting the
access right, navigate to the folder, right click, properties, security.

Michael G. Schneider
 
J

jessie

You could always try putting some

Response.Write "I got to this step"
Response.Write "Now I am at this step"
I did this, and I found the problem occurs in the CreateTextFile. If I cut
this line, it is Ok.
Just one question - you showed the F drive above - this will sound
daft - but its not your CD rom drive is it?
It is not my CD rom.
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top