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

ASP.NET
.NET可复用TCP通信层之消息分派器组件
Asp.Net结合JS在图层上显示记录信息
.NET 2.0里使用强类型数据创建多层应用
ADO.NET Entity Framework 试水——并发
.Net开发:ADO.NET实用技巧两则
使用LINQ来简化编程的7个技巧
VC.NET扩展Windows磁盘清理工具的功能
Asp.Net页面执行流程分析
用asp.net程序备份或还原SQLServer
ASP.NET实现页面间值传递的几种方法介绍
技巧实例:如何在.NET中访问MySQL数据库
asp.net中数据校验部分的封装与应用
ASP.NET中前台javascript与后台代码调用
翻译 一些很酷的.Net技巧
ASP.NET常用的26个优化性能方法
了解VB.NET中的常量与枚举功能
.NET FileStreams将DTD插入XML文件中
Windows CE.Net下矩阵键盘开发设计详解
.Net编程接口剖析系列之比较和排序
在.NET中字符串替换的五种方法

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


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