Method 1: fso
Set fs = creteObject ("scripting.filesystemObject") newfile = server.mappath ("/ asp / chap06 / at / newfile.html") 'New one file /newfile.html, if the file already exists, override it set a = fs.createtextfile (newfile, true) response.write "new file has been established!" a.closefile = server.mappath ("newfile.html") set txt = fs.opentextfile (file, 8, true) 'open Document Data1 = "This sentence is written in the end of the WriteLine method! ~~" txt.writeLine data1data2 = "This sentence is written in Write method! ~~" txt.write data2txt .Close
Method 2: XMLHTTP
<% Set xml = server.createObject ("Microsoft.xmlhttp") 'Replace the following address to your home file address, must use the absolute path of http: //, can not write relative path XML.Open "Get "," http://www.phpup.com ", False xml.Send BodyText = xml.ResponseBody BodyText = BytesToBstr (BodyText," gb2312 ") Set xml = NothingDim fso, MyFileSet fso = CreateObject (" Scripting.FileSystemObject ") Set myfile = fso.createtextfile (Server.mappath ("aa.htm"), true) myfile.writeline (bodytext) myfile.close
other:
1
The following example is, index.asp? Id = 1 / index.asp? Id = 2 / index.asp? Id = 3 / these three dynamic pages, generate ndex1.htm, index2.htm, index3.htm existence The root directory:
<% Dim strUrl, Item_Classid, id, FileName, FilePath, Do_Url, Html_TempHtml_Temp = "
NextHTML_TEMP = HTML_TEMP & "
<% Response.write ("successfully generated file:") Response.write ("
") 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 = Nothingend function%>
2
<% @Language = "vbscript" CODEPAGE = "936"%> <% public tempelatefile, TmpDataSub ofile () opens the file and puts the contents to TMPDATA ON Error ResMe 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 ASSP = ASTREAM from the file. Size if err.Number <> 0 THEN XZ = -18 response.write tempelatefile & "
" Err.clear tmpdata = "" else tmpdata = astream.readtext (assp) end if end subs snave_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 'is written to the data stream Astream . SaveTofile Recfilen, 2 'Save to File End Sub