asp创建文件有两种方法,可以用fso,也可以用stream,这里给你一个stream的例子
=====代码=======
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%
Dim fso,htmlwrite
Dim strTitle,strContent,strOut
'// 创建文件系统对象
Set fso=Server.CreateObject("Scripting.FileSystemObject")
if fso.FileExists(server.MapPath("123.txt")) then
fso.deleteFile(server.MapPath(("123.txt"))
end if
strContent=request.form("content")
strOut=strContent
fileName = "123.txt"
Set htmlwrite=fso.CreateTextFile(Server.MapPath(fileName),true)
'// 写入内容
htmlwrite.WriteLine strOut
'// 关闭
htmlwrite.close
'// 释放文件系统对象
set htmlwrite=Nothing
set fso=Nothing
%>
<%
'下面是保存函数
Function SaveToFile(ByVal strBody, ByVal File)
Dim objStream
Dim RText
RText = Array(0, "")
Set objStream = Server.CreateObject("ADODB.Stream")
With objStream
.Type = 2
.Open
.Charset = "utf-8"
.Position = objStream.Size
.WriteText = strBody
On Error Resume Next
.SaveToFile Server.MapPath(File), 2
If Err Then
RText = Array(Err.Number, Err.Description)
SaveToFile = RText
Err.Clear
Exit Function
End If
.Close
End With
RText = Array(0, "保存文件成功!")
SaveToFile = RText
Set objStream = Nothing
End Function
%>
调用 SaveToFile(文本内容,文件路径)
剩下的自己会写了吧
<%
txtcontent=request.form("content")
PromotionPath = "123.txt"
WriteToHtml PromotionPath,txtcontent
Function WriteToHtml(Fpath,Templet)
Dim FSO,FCr
Set FSO = CreateObject("Scripting.FileSystemObject")
if FSO.FILEExists(Fpath) then
FSO.deleteFILE Fpath
end if
Set FCr = FSO.CreateTextFile(Server.MapPath(Fpath), True)
FCr.Write(Templet)
FCr.Close
Set FCr = Nothing
Set FSO = Nothing
End Function
%>
既然非常简单,我就不用说了。呵呵