日期:2014-05-17  浏览次数:20840 次

写入文件追加位置的问题
VBScript code

<%function writefile(ct,filename,fileEncoder)
  Dim stream
  Set stream = Server.CreateObject("adodb.stream")
  stream.Charset = fileEncoder '设置编码
  stream.Type = 2 '文本
  stream.Mode = 3 'forreadwrite
 stream.Open
  stream.LoadFromFile server.mappath(filename)
stream.Position = stream.Size  
  stream.writeText ct, 1
  stream.SaveToFile server.mappath(filename), 2
  stream.Close
  Set stream = Nothing
End function
%>



这个函数写入数据时是追加在最后,怎么样让追加在最前面?

------解决方案--------------------
<%
function writefile(ct,filename,fileEncoder)
Dim stream
Set stream = Server.CreateObject("adodb.stream")
stream.Charset = fileEncoder
stream.Type = 2
stream.Mode = 3
  stream.Open
ctt=getFile(filename)
stream.writeText ct+ctt, 1
stream.SaveToFile server.mappath(filename), 2
stream.Close
Set stream = Nothing
End function

writefile "ggggggggg","abc.html","gb2312"
response.Write "生成文件件成功!"

%>

<%
function getFile(fn)
Set stm=Server.CreateObject("adodb.stream")
  stm.Type=2
  stm.mode=3 
  stm.charset="gb2312"
  stm.open
  stm.loadfromfile Server.MapPath(fn)
  t1=stm.readtext
  stm.Close
  Set stm=Nothing
  getFile=t1
end function
%>