Text Stream Example

Use the form below to create a new HTML file, when you submit the form the file will be created and displayed at the bottom of the file list as New file


File: test-00.htm Created on: 29/08/2008 10:19:55
File: test-01.htm Created on: 29/08/2008 10:19:57
File: test-02.htm Created on: 12/11/2008 19:44:23
File: test-03.htm Created on: 07/02/2009 16:16:25
File: test-04.htm Created on: 20/02/2009 08:13:19

Complete form to create file

 

Code:
<% 
Set file=Server.CreateObject("Scripting.FileSystemObject")
n = 0

do until lp = "Exit"
     if n < 10 then 
          num = "0" & n
     else
          num = n
     end if
     If (file.FileExists("Drive:\Path\textstream\test" & num & ".htm"))=true Then
          Response.Write("File test" & num & ".htm exists. <a href='textstream/test" & num & ".htm'>test" & num & ".htm</a><br>")
          n = n + 1
     Else
          dim fs, f 
          set fs=Server.CreateObject("Scripting.FileSystemObject") 
          set f=fs.CreateTextFile("Drive:\Path\textstream\test" & num & ".htm",true) 
          f.WriteLine("<html>")
          f.WriteBlankLines(1)
          f.WriteLine("<head>")
          f.WriteLine("<meta http-equiv='Content-Type' content='text/html; charset=windows-1252'>")
          f.WriteLine("<title>New Page Generated by ASP</title>")
          f.WriteLine("</head>")
          f.WriteBlankLines(2)
          f.WriteLine("<body>")
          f.WriteLine("HELLO WORLD!")
          f.WriteLine("<p>&nbsp;</p>")
          f.WriteLine("File created @ " & time & "on " & Date)
          f.WriteLine("<p>&nbsp;</p>")
          f.WriteLine("HELLO WORLD!")
          f.WriteLine("</body>")
          f.WriteLine("</html>")

          f.Close
          set f=nothing
          set fs=nothing
          lp= "Exit"
     End If
loop
set file=nothing
%>
<p>&nbsp;</p>
New file <a href="textstream/test<%=num%>.htm">test<%=num%>.htm</a><br>
						

You will need to change two lines at the top where it has Drive:\Path to your drive and path and you will need to have write permission on the final folder for the IUSER_ServerName user on the web server.

The page differs slightly to the code above in that the code will create a new file each time the page is loaded, where this page waits till the form is submitted before creating the file but both work in the same fassion.