p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

proasp_howto thread: Writing HTML through FileSystemObject


Message #1 by "Markus Hain" <kill@g...> on Tue, 20 Feb 2001 20:15:50
Yes you can, follow these steps
Dim objFSO, objFile, objTextFile, ForWriting, ForAppending (or ForReading)

virPath = "/Any Folder/NewFile.html"  <-- better to give it a asp ext
physPath = Server.MapPath(virPath)

Set objFSO = CreateObject("Scripting.FileSystemObject")
  If objFSO.FileExists(physPath) Then
    Set objTextFile = objFSO.OpenTextFile(physPath, ForAppending)'this wil
 open you new file if you wish to add ASP code afterwards to your newly 
crated file 
  Else 
    Set objTextFile = objFSO.CreateTextFile(physPath, ForWriting) 
End If

objTextFile.Write  strText 'where strText is whatever you want to write to 
that new file

The above code wil not only create a new file for you but will add any 
data you wish to add to the end of it next time you run the above code 
(that's if you dont delete the .html file which is checked by the 
FileExists method of the FileSystem object)


> Hi all
> 
> Is it possible to use something like the FileSystemObject to create a 
new 
> HTML file dynamically from scratch ? Basically taking a parameter 
("name") 
> and writing a new file called "name.html" to the root of the current 
web ?
> Any examples i could use somewhere ?
> 
> many thanks
> 

  Return to Index