Code Bank
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingCode Bank

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old November 30th, 2006, 04:46 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
ASP Free God 45th Plane (27000 - 27499 posts)
 
Join Date: Sep 2004
Location: Israel
Posts: 27,266 Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 6 Days 12 h 6 m 3 sec
Reputation Power: 1791
Post Classic ASP: caching ASP as HTML files.

use the below code to "cache" ASP files as HTML meaning read
the output of given ASP page and save this output as html file
on the server.

Code:
<% Option Explicit %>
<% 
Dim objXMLHTTP, strURL, strHTML
Dim binData, objFSO, strFileName
Dim strFilePath, objFile

strURL="http://www.yourdomain.com/page.asp"

Response.Write("caching page " & strURL & "...<br />")

'initialize xmlhttp component:
Set objXMLHTTP = Server.CreateObject("Microsoft.XMLHTTP")

'send request:
objXMLHTTP.Open "GET", strURL, False
objXMLHTTP.Send

'read raw data:
binData = objXMLHTTP.ResponseBody
Set objXMLHTTP = Nothing

Response.write("page found, size is " & LenB(binData) & " bytes<br />")

'convert binary to ascii data:
strHTML = RSBinaryToString(binData)

'build proper file name:
strFileName = GetFileNameNoExtension(strURL) & ".html"
Response.Write("writing contents to local file " & strFileName & "...<br />")

'initialize file system component:
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

'build file path:
strFilePath = Server.MapPath(strFileName)

'create the file and write contents:
Set objFile = objFSO.CreateTextFile(strFilePath)
objFile.Write(strHTML)
objFile.Close
Set objFSO = Nothing

Response.Write("done. <a href=""" & strFileName & """>" & strFileName & "</a>")

Function GetFileNameNoExtension(strPath)
	Dim index, strFileName
	index = InStrRev(strPath, "\")
	If index=0 Then
		index = InStrRev(strPath, "/")
	End If
	If index=0 Then index = 1
	strFileName = Mid(strPath, index+1, Len(strPath))
	index = InStrRev(strFileName, ".")
	If index=0 Then index = Len(strFileName)+1
	GetFileNameNoExtension = Mid(strFileName, 1, index-1)
End Function

Function RSBinaryToString(xBinary)
	'Antonin Foller, http://www.motobit.com
	'RSBinaryToString converts binary data (VT_UI1 | VT_ARRAY Or MultiByte string)
	'to a string (BSTR) using ADO recordset
	
	Dim RS, LBinary, Binary
	Const adLongVarChar = 201
	
	'MultiByte data must be converted To VT_UI1 | VT_ARRAY first.
	If vartype(xBinary)=8 Then
		Binary = MultiByteToBinary(xBinary)
	Else  
		Binary = xBinary
	End If
	
	Set RS = CreateObject("ADODB.Recordset")
	LBinary = LenB(Binary)
	
	If LBinary>0 Then
		RS.Fields.Append "mBinary", adLongVarChar, LBinary
		RS.Open
		RS.AddNew
		RS("mBinary").AppendChunk Binary 
		RS.Update
		RSBinaryToString = RS("mBinary")
	Else  
		RSBinaryToString = ""
	End If
End Function

Function MultiByteToBinary(MultiByte)
	'© 2000 Antonin Foller, http://www.motobit.com
	' MultiByteToBinary converts multibyte string To real binary data (VT_UI1 | VT_ARRAY)
	' Using recordset
	
	Dim RS, LMultiByte, Binary
	Const adLongVarBinary = 205
	
	Set RS = CreateObject("ADODB.Recordset")
	LMultiByte = LenB(MultiByte)
	If LMultiByte>0 Then
		RS.Fields.Append "mBinary", adLongVarBinary, LMultiByte
		RS.Open
		RS.AddNew
		RS("mBinary").AppendChunk MultiByte & ChrB(0)
		RS.Update
		Binary = RS("mBinary").GetChunk(LMultiByte)
	End If
	MultiByteToBinary = Binary
End Function
%> 


the code is using XMLHTTP to read the contents of the page and
FSO to write those contents into HTML file with same name.

note: for the code to work properly, give full URL!

Happy Programming!
Comments on this post
KiReSt agrees: Nice, just what I am looking for ..soon

Last edited by Shadow Wizard : November 30th, 2006 at 04:50 AM.

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingCode Bank > Classic ASP: caching ASP as HTML files.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT