Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 628
  • Last Modified:

Create Text File using FileSystemObject

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
ksambaraju
Asked:
ksambaraju
2 Solutions
 
iozturkCommented:
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
 
zehebCommented:
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
 
hmtrivediCommented:
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now