ASP generation HTML Method Encyclopedia _asp Foundation

Source: Internet
Author: User
Method One: FSO

Set fs = CreateObject ("Scripting.FileSystemObject")
Newfile=server.mappath ("/asp/chap06/at/newfile.html")
' Create a new file/newfile.html, overwrite it if the file already exists
Set a = fs. CreateTextFile (NewFile, True)
Response.Write "New file has been established! "
A.close
File=server.mappath ("newfile.html")
Set Txt=fs. OpenTextFile (file,8,true) ' open to file that can write data at the end
Data1= "This phrase is written using the WriteLine Method! ~~"
Txt. WriteLine data1
Data2= "This sentence is written using the Write method Oh! ~~"
Txt. Write data2
Txt. Close

Method Two: XMLHTTP

<%
Set XML = Server.CreateObject ("Microsoft.XMLHTTP")
' Replace the following address with the address of your home page, be sure to use the absolute path beginning with http://, cannot write relative path
Xml. Open "Get", "http://www.phpup.com", False
Xml. Send
Bodytext=xml. Responsebody
Bodytext=bytestobstr (BodyText, "gb2312")
Set xml = Nothing
Dim FSO, MyFile
Set fso = CreateObject ("Scripting.FileSystemObject")
Set myfile= FSO. CreateTextFile (server. MapPath ("aa.htm"), True)
MyFile.WriteLine (BodyText)
Myfile.close

Other:

1

The following example is the index.asp?id=1/index.asp?id=2/index.asp?id=3/, the three dynamic
page, which generates ndex1.htm,index2.htm,index3.htm that exist under the root directory:


<%
Dim strurl,item_classid,id,filename,filepath,do_url,html_temp
html_temp= "<UL>"
For I=1 to 3
Html_temp = html_temp& "<LI>"
Item_classid = i
FileName = "Index" &Item_Classid& ". htm"
FilePath = Server.MapPath ("/") & "\" &filename html_temp = html_temp&filepath& "</LI>"
Do_url = "http://"
Do_url = Do_url&request.servervariables ("SERVER_NAME") & "/main/index.asp"
Do_url = do_url& "? Item_classid= "&item_classid


strURL = Do_url
Dim objxmlhttp
Set objxmlhttp = Server.CreateObject ("Microsoft.XMLHTTP")
Objxmlhttp.open "Get", Strurl,false
Objxmlhttp.send ()
Dim Binfiledata
Binfiledata = Objxmlhttp.responsebody
Dim Objadostream
Set objadostream = Server.CreateObject ("ADODB. Stream ")
Objadostream.type = 1
Objadostream.open ()
Objadostream.write (Binfiledata)
Objadostream.savetofile filepath,2
Objadostream.close ()

Next
Html_temp = html_temp& "<UL>"
%>

<%
Response.Write ("Successfully generated file:")
Response.Write ("<BR>")
Response.Write Html_temp
%>

Function Bytestobstr (Body,cset)
Dim objstream
Set objstream = Server.CreateObject ("ADODB.stream")
Objstream. Type = 1
Objstream. Mode =3
Objstream. Open
Objstream. Write body
Objstream. Position = 0
Objstream. Type = 2
Objstream. Charset = Cset
Bytestobstr = objstream. ReadText
Objstream. Close
Set objstream = Nothing
End Function
%>

2

<% @LANGUAGE = "VBSCRIPT" codepage= "936"%>
<%
Public Tempelatefile,tmpdata
Sub Ofile () ' opens the file and places the contents of the file in the Tmpdata
On Error Resume Next
Tmpdata= ""
Set Astream=server.createobject ("ADODB.stream")
astream.type=2 ' File type text
Astream.mode = 3 ' Read and write
Astream.open
Astream.charset = "GB2312" ' character set
Astream.loadfromfile (tempelatefile) ' Load from file
Assp=astream.size
If Err.number<>0 Then
Xz=-18
Response. Write tempelatefile& "<br>"
Err.Clear
Tmpdata= ""
Else
Tmpdata=astream.readtext (ASSP)
End If

End Sub

Sub Save_file ()
Ofile ()
Recfilen=server. MapPath (dts)
Astream.flush
Astream.close
astream.type=2
Astream.mode = 3
Astream.open
Astream.charset = "GB2312"
Astream.position=0
Astream.writetext tmpdata,1 ' write data to stream
Astream.savetofile recfilen,2 ' Save to file
End Sub

function DTS () ' produces random file names
If Len (month (now)) >1 then
Mm=month (now ())
Else
mm= "0" &month (now ())
End If
If Len (today ()) >1 Then
D=day (now ())
Else
d= "0" &day (now ())
End If
If Len (hour (now)) >1 then
H=hour (now ())
Else
H= "0" &hour (now ())
End If
If Len (minute (now)) >1 then
M=minute (now ())
Else
m= "0" &minute (now ())
End If
If Len (second (now)) >1 then
S=second (now ())
Else
s= "0" &second (now ())
End If
Randomize
upperbound=9999
lowerbound=1000
Rds=int ((upperbound-lowerbound + 1) * Rnd + lowerbound)
dts= "htm/" &year (Now ()) &mm&d&h&m&s&rds& ". htm"
End Function
Title=request. Form ("title")
Content=request. Form ("content")
Tmpdata=replace (Tmpdata, "<title></title>", title) ' to support the replacement of submitting content
Tmpdata=replace (Tmpdata, "<content></content>", content)
Tempelatefile=server. MapPath ("tempelate/1.htm") ' Stencil file
Save_file ()
%>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.