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

ASP.NET
.Net基础:在ASP.net中网站访问量统计方法
Asp.Net 建立一个在线 RSS 新闻聚合器
ASP.NET从字符串中查找字符出现次数的方法
了解ASP.NET中的IFRAME框架挂马
JAVA和.NET两个平台对于安全功能的比较
.NET中*延迟*特性的几个陷阱
使用ASP.NET Global.asax 文件
在.NET环境下为网站增加IP过滤功能
如何实现.net程序的进程注入
在.Net Micro Framework中显示汉字
引以为戒 .NET开发者常犯的错误
WinForm程序中使用控制台作为输出窗口
浅谈如何使用 Lambda 表达式做抽象代表
.Net基础:C#中对DatagridView部分常用操作
ASP.NET LinkButton组件编程浅析
ASP.NET中使用AJAX中的方式
ASP.NET组件设计之生命周期详解
asp.net下web控件点评
.Net应用:ASP.NET中使用AJAX中的方式
.Net基础:ASP.NET中的javascript操作

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 67 ::
收藏到网摘: 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 !!!" )
%>