VB icon

Create a HTML-file from ASP

Submitted on: 1/5/2015 5:20:00 PM
By: Basie van Heerden (from psc cd)  
Level: Beginner
User Rating: By 5 Users
Compatibility: ASP (Active Server Pages)
Views: 1395
     To create a static HTML-page from an ASP, rather than repeatedly recreate the same info in the ASP-page
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
' Name: Create a HTML-file from ASP
' Description:To create a static HTML-page from an ASP, rather than repeatedly recreate the same info in the ASP-page
' By: Basie van Heerden (from psc cd)
' Assumes:The code is fully/heavily/well commented

' How to create a .txt-file. (or .html, .asp, whatever)
' In this example the file is only created when a condition, which
' YOU supply, is met. I use it to create a static .html-page once a
' day in order to diminish time spent on gathering yesterday's data,
' doing calculations on it, and then send it as html to the client.
' By doing this once and then store the info as a static html-page,
' I save on time and server-resources.
' I hope you find some use for this code!
' Basie van Heerden (basie.v.heerden@ast.co.za)
'ALWAYS first declare the variables you're going to use!
Dim objFName
dim FName
Dim HTMLname
'This subroutine is where the file is created, but only if the set
'condition is met, else this page only redirects to the previously
'created page
Sub MakeHTML()
	On Error Resume Next
	'Put the path and name of the file to be created in a variable
	HTMLname = "c:\inetpub\whatever\TestPage.htm"
	'Tell the system that you want to create a file
	set objFName = server.CreateObject("Scripting.FileSystemObject")
	'Open the .html-file, overwrite the existing file, unicode
	set FName = objFName.CreateTextFile(HTMLname,8,True)
	'Write the whole file. It can be HTML, like in this example, or
	'it can be another ASP-page, a text file, whatever.
FName.writeline("<BODY bgcolor=white>")
FName.writeline("Hello world! Whatever...")
'Close and clean up behind you...
	set FName = nothing
End sub
'Create the file on a given condition, eg when the page is accessed
'for the first time each day/week/month/whatever. After that and
'until the condition is met, just redirect to the created HTML-page.
if condition then
end if
Response.Redirect "TestPage.htm"

Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)

Other User Comments

 There are no comments on this submission.

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)

To post feedback, first please login.