阅读文章(首页/程序开发/.NET教程/)

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

[日期:2004-06-25] 来源:  作者: [字体: ]

ASP.NET中操作文件的例子

1、写文件
writefile.ASPx

<%@ Import Namespace="System.IO" %> '引入所需的NameSpace
<%
Response.write("Writing the content into Text File in ASP.NET
")
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
")
Dim streamreaderobj As StreamReader '声明一个StreamReader对象
Dim filecont As String '声明一个变量保存读出的内容
streamreaderobj = File.OpenText( "c:\ASPnet.txt" ) '打开文件赋值到StreamReader对象
Do '按行循环读取文件内容
filecont = streamreaderobj.ReadLine()
Response.Write( filecont & "
" )
Loop Until filecont = ""
streamreaderobj.Close '关闭StreamReader对象
Response.write("
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 !!!" )
%>



阅读:
录入:

评论 】 【 推荐 】 【 打印
上一篇:关于两代语言.C/C++,java/c#
下一篇:在ASP.NET中处理 datetime 的一些通用函数(vb)
相关文章      
本文评论
发表评论


点评: 字数
姓名:

  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款