如何编写ASP可是其修改指定文件指定行的内容

来源:百度知道 编辑:UC知道 时间:2024/05/22 02:21:13
例如现在有xigai.asp
里面有一个表单,提交后
将001.asp第12行的数据替换为xigai.asp表单提交的数据.
(提交的数据仍在001.asp的第12行,覆盖而已)
谢谢~~
那如果我用下面的代码写入文件,怎么改可以变成写入(覆盖)到c:\testfile.txt 的第三行的?
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("c:\testfile.txt", 2, True, TristateUseDefault)
f.Write "123"
f.Close
%>

专门定义一个变量保存001.asp第12行的数据,单独放在setep.asp里,然后在001.asp里包含setep.asp。

setep.asp代码:
<%
Dim data001
data001 = "001.asp第12行的数据"
%>

xigai.asp代码:
<%
Dim newdata
Dim objFSO
Dim objFile
newdata = Request.Form("newdata") 'xigai.asp提交的数据
newdata = "<%" & vbCrLf &_
"Dim data001" & vbCrLf &_
"data001 = """ & newdata & """" & vbCrLf &_
"%\>"
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objFile=objFSO.CreateTextFile(Server.MapPath("setup.asp"),True)
objFile.Write newdata
objFile.Close
Set objFile=Nothing
Set objFSO = Nothing
%>

用FSO的UPDATA
定义一常量
A=xigai.asp
用另一页面更新这一页面中的A为001.asp就行了,