<p>FSO 读出TXT文件</p> <p><!--#include file="dbconn.asp"--><br /> &lt;%<br /> function ReadFile(filename)<br /> on error resume next<br /> err.clear<br /> &#39;ASP的一种校错方法<br /> Const ForReading = 2<br /> Const Create = false<br /> Dim FSO<br /> DIM TS<br /> DIM filepath<br /> DIM thefile<br /> Dim content</p> <p>&#39;---------------操作地址</p> <p>Set FSO=server.createobject(&quot;scripting.filesystemobject&quot;)<br /> filepath=server.MapPath(&quot;temp&quot;) ./记录本存放的文件夹</p> <p>if err.number&lt;&gt;0 then<br /> response.Write &quot;目录不存在&quot;<br /> response.End<br /> end if</p> <p>&#39;filename=&quot;test.txt&quot; ---------test.txt为你从数据库里读出的文件名<br /> thefile=filepath&amp;&quot;/&quot;&amp;filename<br /> Set TS = FSO.OpenTextFile(thefile,1)</p> <p>do until Ts.AtEndOfStream<br /> Response.Write (&quot;&quot;&amp;TS.ReadLine&amp;&quot;&quot;)<br /> response.write(&quot;<br /> &quot;)<br /> loop</p> <p>Set TS = Nothing<br /> Set FSO = Nothing<br /> end function<br /> %&gt;</p> <p>&lt;%<br /> dim id<br /> dim filename<br /> id=6<br /> Set rs=Server.CreateObject(&quot;ADODB.Recordset&quot;)<br /> sql=&quot;select * from yuan where id=&quot;&amp;id<br /> rs.open sql,cn,1,1<br /> filename=rs(&quot;fileload&quot;)<br /> %&gt;</p> <p>&lt;% readfile(filename) %&gt;</p>
T:0.006420s,M:245.5 KB
返回顶部 留言