How to save ASP output into HTML file

I have a complex ASP page, It will take a log time to load. How I save the ASP output into HTML file, So next time we first chech if the html file exists, if it exists, it will directly load html file, no need to go to ASP, otherwith we will load ASP page. Could you provide some sample codes? Thank you  
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

If you have access to it you can save files using the fileSystemObject. The following code will create a file and write one line to it.

dim objFS, MyFile
set objFS = server.CreateObject("Scripting.FileSystemObject")
Set MyFile = objFS.CreateTextFile( Server.MapPath("/files/testfile.htm"), true)
MyFile.WriteLine("This is a test.")
set MyFile = nothing
set objFS = nothing

You probably want to double check your ASP and data access methods for bottlenecks. But if you MUST write an HTML file, this piece of code should work fine. On your current ASP, substitute "Response.Write" for "WriteOut"

Dim oFSO
Set oFSO = CreateObject("Scripting.FileSystemObject")

Dim sFileName       :sFileName = "Sample.html"
Dim sPhysicalFile   :sFilePhysicalFile = "C:\Inetpub\root\test\" & sFileName
Dim sURL            :sURL = "" & sFileName

Dim oFile

'Check if saved HTML exists or not
'sForceCreate is a variable that, when set to "y" forces the code
'to update the saved HTML file. This can be fetched from the
'querystring or whatever.
Dim sForceCreate
sForceCreate = Request("ForceCreate")
If oFSO.FileExists(sPhysicalFile) And sForceCreate <> "y" Then
    Set oFile = oFSO.GetFile(sPhysicalFile)
    'Also, we can check if the file is older than 10 days
    'If it is, recreate the file
    If DateDiff("y",oFile.DateCreated,Now()) < 10 Then
        Set oFile = Nothing
        Set oFSO = Nothing
        Response.Redirect sURL
    End If    
End If

'Create a text file
'True indicates that we can overwrite an existing file
Set oFile = oFSO.CreateTextFile(sPhysicalFile, True)

Sub WriteOut(sString)
    'Will take the sString and WriteOut it and Write it to a file.
    Response.Write sString
    oFile.WriteLine sString
End Sub


Set oFile = Nothing
Set oFSO = Nothing

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The really SIMPLEST way is to install either Apache or Squid in front of the IIS server in proxy cache mode.

You can set up the caching not only to cache the static pages returned from IIS (thus reduce the load there) but also dynamicaly generated pages. You can even discard these pages at regular intervals (let's say they're stock quotes or the like which need to be recalculated every hour). Considering that the software is free it'll cost you just the machine (I think you should run it on a separate machine for roduction purposes) which is a damn sight cheaper than rewriting the software. And remember "Never touch a running system".
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.