当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > 在ASP.NET中操作文件的例子(VB)

ASP.NET
Validation服务器控件:ValidationSummary控件
ASP.NET教程:URL重写的实现
ASP.NET巧妙实现无刷新更换CSS样式
ASP.NET教程:eval()函数详解
LINQ学习笔记:结构化且类型安全的查询
LINQ学习笔记:Lambda表达式
LINQ学习笔记:复合查询和Lambda表达式语法
LINQ学习笔记:查询是怎么执行的
LINQ学习笔记:子查询和延迟执行
LINQ学习笔记:创建更加复杂查询的策略
LINQ学习笔记:对象初始化器
LINQ学习笔记:解释查询(Interpreted Queries)
LINQ学习笔记:表达式树
LINQ学习笔记:过滤Filtering
LINQ学习笔记:选取Select
LINQ学习笔记:Join和Group Join
LINQ学习笔记:排序Ordering
LINQ学习笔记:分组Grouping
LINQ学习笔记:Set操作符
LINQ学习笔记:转换方法

在ASP.NET中操作文件的例子(VB)


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 56 ::
收藏到网摘: n/a

在ASP.NET中操作文件的例子

1、写文件
writefile.aspx

<%@ Import Namespace="System.IO" %> '引入所需的NameSpace
<%
Response.write("Writing the content into Text File in ASP.NET <BR>")
Dim strwriterobj As StreamWriter '声明一个StreamWriter对象
strwriterobj= File.CreateText("c:\aspnet.txt") '新建一个文本文件,赋值给StreamWriter对象
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")
%>

2、读文件
readfile.aspx

<%@ Import Namespace="System.IO" %>
<%
Response.write("Reading the content from the text file ASPNET.TXT <br>")
Dim streamreaderobj As StreamReader '声明一个StreamReader对象
Dim filecont As String '声明一个变量保存读出的内容
streamreaderobj = File.OpenText( "c:\aspnet.txt" ) '打开文件赋值到StreamReader对象
Do '按行循环读取文件内容
filecont = streamreaderobj.ReadLine()
Response.Write( filecont & "<br>" )
Loop Until filecont = ""
streamreaderobj.Close '关闭StreamReader对象
Response.write("<br> Done with reading the content from the file aspnet.txt")
%>

3、删除文件
Filedelete.aspx

<%@ Import Namespace="System.IO" %>
<%
File.Delete("c:\aspnet.txt" ) '删除文件
Response.write("The File aspnet is deleted successfully !!!" )
%>