在ASP.NET中設(shè)置文件的例子(VB)
發(fā)表時(shí)間:2023-08-17 來源:明輝站整理相關(guān)軟件相關(guān)文章人氣:
[摘要]在ASP.NET中操作文件的例子 1、寫文件writefile.aspx<%@ Import Namespace="System.IO" %> '引入所需的N...
在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 '聲明一個(gè)StreamWriter對(duì)象
strwriterobj= File.CreateText("c:\aspnet.txt") '新建一個(gè)文本文件,賦值給StreamWriter對(duì)象
strwriterobj.WriteLine( "Welcome to wonderfull world of ASP.NET Programming" )
'向文件中寫內(nèi)容
strwriterobj.Close '關(guān)閉對(duì)象
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 '聲明一個(gè)StreamReader對(duì)象
Dim filecont As String '聲明一個(gè)變量保存讀出的內(nèi)容
streamreaderobj = File.OpenText( "c:\aspnet.txt" ) '打開文件賦值到StreamReader對(duì)象
Do '按行循環(huán)讀取文件內(nèi)容
filecont = streamreaderobj.ReadLine()
Response.Write( filecont & "<br>" )
Loop Until filecont = ""
streamreaderobj.Close '關(guān)閉StreamReader對(duì)象
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 !!!" )
%>