教程集 www.jiaochengji.com
教程集 >  脚本编程  >  Asp.net  >  正文 ASP.NET读写文件教程

ASP.NET读写文件教程

发布时间:2016-12-05   编辑:jiaochengji.com
教程集为您提供ASP.NET读写文件教程等资源,欢迎您收藏本站,我们将为您提供最新的ASP.NET读写文件教程资源
好了我们以vb.net的形式来写asp.net对文件的读写操作吧,这个在其它的编程里面也一样可以对文件进行读与写了.

读取和写入文件使用ASP.NET ( VB )中


阅读和写作的档案内容使用ASP.NET 2.0和C # 2.0其实是非常简单的。

首先,您将需要Imports System.IO命名空间。

Imports System.IO;

我们感动我们的网站服务器的智慧和发现他们是难以置信的专业。其安装非常容易,我们启动和运行中没有时间。

System.IO命名空间包含类型,使阅读和书写的文件和数据流,并类型,提供基本的文件和目录的支持。使用类文件, DirectoryInfo在这里。

使用DirectoryInfo类典型的操作,如复制,移动,重命名,创建和删除目录。

使用文件级的典型操作,如创建,打开,删除,添加,复制,移动和重新命名文件。

使用ReadAllText方法打开一个文本文件,内容所有的档案,然后关闭该文件。

使用WriteAllText方法创建一个新文件,写入指定的字符串的文件,然后关闭该文件。如果目标文件已经存在,它是覆盖。

我们使用buttonDisplay_Click活动,以显示该文件的内容和使用buttonSave_Click甚至保存为一个文件。

代码如下。www.jiaochengji.com

Protected Sub buttonDisplay_Click(ByVal sender As Object, ByVal e As System.EventArgs)

Dim FilePath As String
FilePath = txtBoxInput.Text
If File.Exists(FilePath) Then
textBoxContents.Text = File.ReadAllText(FilePath)
Else
Response.Write("<script language='javascript'>window.alert(www.jiaochengji.com);</script>")
Return
End If

End Sub

Protected Sub buttonSave_Click(ByVal sender As Object, ByVal e As System.EventArgs)

Dim Folder As New DirectoryInfo(textboxPath.Text)
If Folder.Exists Then
If textboxName.Text <> String.Empty Then
Dim FilePathSave As String = Folder.ToString() textboxName.Text File.WriteAllText(FilePathSave, textBoxContents.Text)
Else
Response.Write("<script language='javascript'>window.alert('Please enter file name');</script>")
End If
Else
Response.Write("<script language='javascript'>window.alert('Folder not found');</script>")
End If

End Sub

是的,这是能够找到一个很好的网页主机。有时需要一段时间。经过几次努力,我们去与服务器智力,并已非常高兴。他们是最专业的,友好的客户服务和技术知识的东道国,我们发现迄今。

前ReadWriteTextCSharp.aspx页看上去像这样:

<table width="600" border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#cccccc">

<tr>
<td bgcolor="#eeeeee" class="header1">
<fieldset>
<legend>ReadWriteTextCsharp</legend>
<div>
<asp:Label ID="Label1" runat="server" Text="Enter path of file to be examined and click Display"></asp:Label><br />
<asp:TextBox ID="txtBoxInput" runat="server" Width="451px"></asp:TextBox>
<asp:Button ID="buttonDisplay" runat="server" Text="Display" OnClick="buttonDisplay_Click" /><br />
<fieldset>
<legend>Content of file</legend>
<asp:Label ID="Label2" runat="server" Text="You can edit the content and save as a file."></asp:Label><br />
<table>
<tr>
<td>
<asp:TextBox ID="textBoxContents" runat="server" tabIndex="0" height="200px" textMode="MultiLine" width="450px"></asp:TextBox>
</td>
</tr>
</table>
<fieldset>
<legend>Save as</legend>Path:
<asp:TextBox ID="textboxPath" runat="server" Width="237px"></asp:TextBox>File name:
<asp:TextBox ID="textboxName" runat="server" Width="93px"></asp:TextBox>
<asp:Button ID="buttonSave" runat="server" Text="Save As" Width="66px" OnClick="buttonSave_Click" /></fieldset>
</fieldset>
</div>
</fieldset>
</td>
</tr>

</table>

您可能感兴趣的文章:
asp.net读写xml文件的代码一例
asp.net c读取写文件操作代码
c# 二进制方式读取文本文件的实现代码
C#读写xml文件的简单例子
Jquery 插件开发笔记整理
ASP.NET读写文件教程
asp.net 文件上传、下载(二进制流保存到数据库)的代码
学习php写入文件内容的方法
ASP.NET生成静态网页的方法
ASP.NET中TreeView控件使用小结

[关闭]
~ ~