首页 > 编程 > .NET > 正文

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

2024-07-10 12:57:59
字体:
来源:转载
供稿:网友
在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 !!!" )
%>
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表