写文本:StreamWriter objSw = File.CreateText(FileName);
objSw.Write(Content);
objSw.Close();
读文本:StreamReader objSr = File.OpenText(FileName);
Response.Write(objSr.ReadToEnd());
objSr.Close();
objSw.Write(Content);
objSw.Close();
读文本:StreamReader objSr = File.OpenText(FileName);
Response.Write(objSr.ReadToEnd());
objSr.Close();
解决方案 »
- 关于.net下载FTP的问题
- 多于户同时访问同一个表时(解决方案)
- 仿淘宝购物车,DataList加CheckBox
- 传参问题?
- 请教:在aspx页面里怎么调用CSS样试文件呀?
- 解决方案在不同vs版本中打开
- <<ASP.NET数据库入门经典.C#编程篇>>最后一章的源代码的数据库安装不上!请教看过该书的朋友
- 谁能像叙述一下动态生成html是怎么一个过程,原理???
- 加入微软官网的防止重复提交的MsdnModule后,TreeView类的打开和关闭树形功能不能使用了。
- 使用HttpWebRequestHttpWebResponse读取servlet网页出现中文乱码问题(难!!!)
- 我用的是datatread对像,如果做分页呀?
- 看到有些网站发贴,不仅能看到发贴人的代理IP,还能看到lan的IP,如何做的?
"VALUES ("+ TextBox1.Text + ",'"+ TextBox2.Text +"')";
前面已经提到,要想在ASP.NET 页面中进行文件处理,必须要有"System.IO"名称空间。所以,第一步就是引入这个名称空间:
<%@ Import Namespace="System.IO" %>
下一步,就是创建一个文本文件,并将这个文本文件分配给一个流书写对象,这样就可以向文本文件中写入内容了。用以下一段代码来完成这个任务:
writefile.aspx
<%@ Import Namespace="System.IO" %>
<%
Response.write("Writing the content into Text File in ASP.NET<BR>") "声明流书写对象
Dim strwriterobj As StreamWriter " 创建文本文件,分配textfile对象
strwriterobj= File.CreateText("c:aspnet.txt" ) " 写入内容
strwriterobj.WriteLine( "Welcome to wonderfull world of ASP.NET Programming" ) " 完成操作,关闭流对象
strwriterobj.Close Response.write("Done with the creation of text file and writing content into it")
%> 这样就完成了!
现在让我来继续进行下一个任务,从刚才创建的文本文件中读取内容。 从文件中读取内容与向文件中写入内容大致相同,只是要注意一下下面的两件事:
1. 文件读取使用StreamReader类 2. 当使用了Readline方法时,将要被读取的文本文件的结尾处会用一个空字符串("")来标记。
现在开始编写代码从前面创建的aspnet.txt 文件中读取内容:
readfile.aspx
<%@ Import Namespace="System.IO" %>
<%
Response.write("Reading the content from the text file ASPNET.TXT<br>")
" 创建流读取对象
Dim streamreaderobj As StreamReader
" 声明变量,以存放从文件中读取的内容
Dim filecont As String
" 打开文本文件,分配给流读取对象
streamreaderobj = File.OpenText( "c:aspnet.txt" )
" 逐行读取文件内容
Do
filecont = streamreaderobj.ReadLine()
Response.Write( filecont & "<br>" )
Loop Until filecont = ""
" 完成读取操作后,关闭流读取对象
streamreaderobj.Close
Response.write("<br>Done with reading the content from the file aspnet.txt")
%>
就这样了,如果有什么不懂和不详细!?
可以问我QQ81698052 EMAIL:[email protected]