检查文件是否存在、创建文件、拷贝文件、移动文件、删除文件、读取文件信息、创建文件、查看文件列表、文本文件写入、读取文本文件。
前台代码:
<%@ Page language="c#" Codebehind="FileTest.aspx.cs" AutoEventWireup="false" Inherits="NetTest.FileTest" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > <HTML> <HEAD> <title>FileTest</title> <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1"> <meta name="CODE_LANGUAGE" Content="C#"> <meta name="vs_defaultClientScript" content="JavaScript"> <link href="Css/BasicLayout.css" rel="stylesheet" type="text/css"> <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"> </HEAD> <body MS_POSITIONING="GridLayout"> <form id="Form1" method="post" runat="server"> <table class="GbText" align="center" border="1" width="80%" style="BORDER-COLLAPSE: collapse" borderColor="#cccccc"> <tr> <td height="25" colspan="4" align="center"><font style="FONT-WEIGHT: bold; FONT-SIZE: 11pt">关于File的一些例子</font></td> </tr> <tr> <td height="25" align="right">输入文件路径:</td> <td height="25" align="left" style="WIDTH: 179px"> <asp:TextBox id="txtFilePath1" runat="server"></asp:TextBox></td> <td height="25" align="center"> <asp:Label id="lbMessage1" runat="server"></asp:Label></td> <td height="25" align="center"><FONT face="宋体"> <asp:Button id="btnTest" runat="server" Text="检查文件是否存在"></asp:Button></FONT></td> </tr> <tr> <td height="25" align="right">输入文件路径:</td> <td height="25" align="left" style="WIDTH: 179px"> <asp:TextBox id="txtFilePath2" runat="server"></asp:TextBox></td> <td height="25" align="center"> <asp:Label id="lbMessage2" runat="server"></asp:Label></td> <td height="25" align="center"><FONT face="宋体"> <asp:Button id="btnCreate" runat="server" Text="创建文件"></asp:Button></FONT></td> </tr> <tr> <td height="25" align="right">输入文件路径:<br> 输入目的文件路径:</td> <td height="25" align="left" style="WIDTH: 179px"> <P> <asp:TextBox id="txtFilePathM" runat="server"></asp:TextBox><br> <asp:TextBox id="txtFilePathT" runat="server"></asp:TextBox></P> </td> <td height="25" align="center"> <asp:Label id="lbMessage3" runat="server"></asp:Label></td> <td height="25" align="center"><FONT face="宋体"> <asp:Button id="btnCopy" runat="server" Text="拷贝文件"></asp:Button> <asp:Button id="btnMove" runat="server" Text="移动文件"></asp:Button></FONT></td> </tr> <tr> <td height="25" align="right">输入文件路径:</td> <td height="25" align="left" style="WIDTH: 179px"> <asp:TextBox id="txtDeleteFile" runat="server"></asp:TextBox></td> <td height="25" align="center"> <asp:Label id="lbMessage4" runat="server"></asp:Label></td> <td height="25" align="center"><FONT face="宋体"> <asp:Button id="btnDelete" runat="server" Text="删除文件"></asp:Button></FONT></td> </tr> <tr> <td height="25" align="right">输入文件路径:</td> <td height="25" align="left" style="WIDTH: 179px"> <asp:TextBox id="txtFileInfo" runat="server"></asp:TextBox></td> <td height="25" align="center"> <asp:Label id="lbMessage5" runat="server"></asp:Label><br> <asp:Label id="lbDir" runat="server" Visible="False"></asp:Label><br> <asp:Label id="lbLength" runat="server" Visible="False"></asp:Label><br> <asp:Label id="lbTime" runat="server" Visible="False"></asp:Label><br> <asp:Label id="lbEdit" runat="server" Visible="False"></asp:Label><br> <asp:Label id="lbAtt" runat="server" Visible="False"></asp:Label></td> <td height="25" align="center"><FONT face="宋体"> <asp:Button id="btnInfo" runat="server" Text="读取文件信息"></asp:Button></FONT></td> </tr> <tr> <td height="25" align="right">输入文件路径:</td> <td height="25" align="left" style="WIDTH: 179px"> <asp:TextBox id="txtDirectory" runat="server"></asp:TextBox></td> <td height="25" align="center"> <asp:Label id="lbMessage6" runat="server"></asp:Label></td> <td height="25" align="center"><FONT face="宋体"> <asp:Button id="btnCreateDir" runat="server" Text="创建文件夹"></asp:Button></FONT></td> </tr> <tr> <td height="25" align="right">输入文件路径:</td> <td height="25" align="left" style="WIDTH: 179px"> <asp:TextBox id="txtLookDir" runat="server"></asp:TextBox></td> <td height="25" align="center"> <asp:Label id="lbMessage7" runat="server"></asp:Label> <asp:ListBox id="lstDir" runat="server" Visible="False" Height="80px" Width="65px"></asp:ListBox></td> <td height="25" align="center"><FONT face="宋体"> <asp:Button id="btnLook" runat="server" Text="查看文件列表"></asp:Button></FONT></td> </tr> <tr> <td height="25" align="right">输入文件路径:<br> 输入内容:</td> <td height="25" align="left" style="WIDTH: 179px"> <asp:TextBox id="txtFileWrite" runat="server"></asp:TextBox><br> <asp:TextBox id="txtWriteInfo" runat="server" Height="80px" Width="152px" TextMode="MultiLine"></asp:TextBox></td> <td height="25" align="center"> <asp:Label id="lbMessage8" runat="server"></asp:Label></td> <td height="25" align="center"><FONT face="宋体"> <asp:Button id="btnWrite" runat="server" Text="文本文件写入"></asp:Button></FONT></td> </tr> <tr> <td height="25" align="right">输入文件路径:<br> 输入内容:</td> <td height="25" align="left" style="WIDTH: 179px"> <asp:TextBox id="txtReadFile" runat="server"></asp:TextBox><br> <asp:TextBox id="txtReadInfo" runat="server" Height="80px" Width="152px" TextMode="MultiLine" Visible="False"></asp:TextBox></td> <td height="25" align="center"> <asp:Label id="lbMessage9" runat="server"></asp:Label></td> <td height="25" align="center"><FONT face="宋体"> <asp:Button id="btnRead" runat="server" Text="读取文本文件"></asp:Button></FONT></td> </tr> </table> </form> </body> </HTML> |
后台代码:
using System; #region Web 窗体设计器生成的代码 } private void btnTest_Click(object sender, System.EventArgs e) private void btnCreate_Click(object sender, System.EventArgs e) private void btnCopy_Click(object sender, System.EventArgs e) private void btnMove_Click(object sender, System.EventArgs e) private void btnDelete_Click(object sender, System.EventArgs e) private void btnInfo_Click(object sender, System.EventArgs e) private void btnCreateDir_Click(object sender, System.EventArgs e) private void btnLook_Click(object sender, System.EventArgs e) private void btnWrite_Click(object sender, System.EventArgs e) private void btnRead_Click(object sender, System.EventArgs e) |