?
Solved

Create Text File using FileSystemObject

Posted on 2003-03-05
6
Medium Priority
?
617 Views
Last Modified: 2006-11-17
Hi All,

In asp I used the following code to create a file.
<%
   dim fso, objFile
   set fso = server.CreateObject("scripting.FileSystemObject")
   set objFile = fso.CreateTextFile("C:\test1.txt", True)
   objFile.writeline "Hello World"
%>
Its not creating the file. Infact the web server is getting hanged when executing the page with the above code. Can any one give me a solution for this.

Thanks in advance.
0
Comment
Question by:ksambaraju
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 4

Accepted Solution

by:
iozturk earned 100 total points
ID: 8070411
Do not forget to close the file. Modify your code as

<%
  dim fso, objFile
  set fso = server.CreateObject("scripting.FileSystemObject")
  set objFile = fso.CreateTextFile("C:\test1.txt", True)
  objFile.writeline "Hello World"
  fso.close
%>

before attempting to run this asp file stop and start iisadmin service from services.
0
 
LVL 1

Assisted Solution

by:zeheb
zeheb earned 100 total points
ID: 8071524
also you would'nt want to forget to free the "FileSystemObject" object from memory by issue the command:
Set objFile = Nothing
Set fso = Nothing
0
 

Expert Comment

by:hmtrivedi
ID: 8201758
use this:

<%
dim objfso=server.createobject("Scripting.FileSystemObject")
set objfile=objfso.Opentextfile ("C:\myfile.txt",2,true)
objfile.write "contents of myfile"
objfile.close
set objfile=nothing
set objfso=nothing
%>

the attribute true in opentextfile creates the file if it is absent and 2 opens it for appending. this should solve your problem.
0

Featured Post

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question