Codefixer - ASP tutorials, resources and software
New MS SQL 2008 Available – DiscountASP.NET
Home   Articles   Resources   ASP directory   ASP Tutorials   Code Snippets   ASP Applications   Forum
Monday 6 October
MembersPro PayPal - ASP Membership software

USA & Europe Data Centers – DiscountASP.NET


ASP Partner ASP Partner ASP Partner more partners...

Create a text file with ASP using the File Scripting Object

<%
Dim oFilesys
'this line creates an instance of the File Scripting Object named oFilesys
Set oFilesys = Server.CreateObject("Scripting.FileSystemObject")
'check if the file 'newfile.txt' does not exist
If NOT oFilesys.FileExists("C:\FSOfolder\newfile.txt") Then
'create file and place in its folder 'fsofolder' which we created on the C Drive
oFilesys.CreateTextFile("C:\FSOfolder\newfile.txt")
Else
'if the file exists let us know
Response.Write "This file already exists."
End If
'this line destroys the instance of the File Scripting Object named oFilesys
Set oFilesys = Nothing
%>

The code below writes text to the file we created.

<%
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim oFilesys, oFile
Set oFilesys = CreateObject("Scripting.FileSystemObject")
Set oFile = oFilesys.OpenTextFile("C:\FSOfolder\newfile.txt", ForWriting, True)
oFile.Write "Hello world!"
%>

The code below appends text to our existing file 'newfile.txt'.

<%
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim oFilesys, oFile
Set oFilesys = CreateObject("Scripting.FileSystemObject")
Set oFile = oFilesys.OpenTextFile("C:\FSOfolder\newfile.txt", ForAppending, True)
oFile.Write "This is my text file."
%>


Here's example code on how to open a file and write out it's contents.





If you have any code snippets to share with full credit given then send an email to Codesnippets - You'll receive full credit and a link back to your site.

ASP.NET 3.5/2.0 Web Hosting: 3 Months FREE – Click Here!




About | Contact | Advertise | Feedback | Hire Us | Link

Site developed by Michael Wall - Web Design Belfast N.Ireland.
Copyright © 2000-2008. All rights reserved.

Do you intend to move to ASP.NET or have you already?
Yes will do
Have done
ASP does fine
Not a priority


Directory Software