文件的删除和文件信息的读取
<table border="1">
??????????? <tr>
??????????????? <td colspan="2" style="color: #660066;">
??????????????????? 刪除文件:
??????????????? </td>
??????????? </tr>
??????????? <tr>
??????????????? <td style="font-size: 10pt">
??????????????????? 請輸入要刪除文件的路徑:
??????????????? </td>
??????????????? <td style="width: 158px">
??????????????????? <asp:TextBox ID="FileTextBox" runat="server"></asp:TextBox>
??????????????? </td>
???????????????
??????????? </tr>
??????????? <tr>
??????????????? <td colspan="2">
??????????????????? <asp:Label ID="MsgLabel" runat="server" ForeColor="red"></asp:Label>
??????????????? </td>
??????????? </tr>
??????????? <tr>
??????????????? <td align="center" colspan="2">
??????????????????? <asp:Button ID="ExistButton" runat="server" Text="刪除" OnClick="ExistButton_Click"? />
??????????????? </td>
??????????? </tr>
??????? </table>
using System.IO;
public partial class Delete : System.Web.UI.Page
 {
 ??? protected void Page_Load(object sender, EventArgs e)
 ??? {
??? }
 ??? protected void ExistButton_Click(object sender, EventArgs e)
??? {
 ??????? try
 ??????? {
 ??????????? if (!File.Exists(FileTextBox.Text))
 ??????????? {
 ??????????????? MsgLabel.Text = "該文件不存在";
 ??????????? }
 ??????????? else
 ??????????? {
 ????????????????File.Delete(FileTextBox.Text);
??????????????? MsgLabel.Text = "刪除文件成功!";
 ??????????? }
 ??????? }
 ??????? catch (Exception ee)
 ??????? {
 ??????????? MsgLabel.Text = "操作失敗! 失敗的原因是:" + ee.ToString();
 ??????? }
 ??? }
 }
 2:讀取文件詳細信息:
<table border="1">
 ??????????? <tr>
 ??????????????? <td colspan="2" style="color: #660066;">
 ??????????????????? 獲取文件的基本信息:
 ??????????????? </td>
 ??????????? </tr>
 ??????????? <tr>
 ??????????????? <td style="font-size: 10pt">
 ??????????????????? 請輸入要查看文件的路徑:
 ??????????????? </td>
 ??????????????? <td style="width: 158px">
 ??????????????????? <asp:TextBox ID="FileNameTextBox" runat="server"></asp:TextBox>
 ??????????????? </td>
 ??????????????? 
 ??????????? </tr>
 ??????????? <tr>
 ??????????????? <td colspan="2">
 ??????????????????? <asp:Label ID="MsgLabel" runat="server" ForeColor="red"></asp:Label><br/>
 ??????????????????? <asp:Label ID="DirLabel" runat="server"></asp:Label><br/>
 ??????????????????? <asp:Label ID="LengthLabel" runat="server" Text="Label"></asp:Label><br/>
 ??????????????????? <asp:Label ID="CreationTimeLabel" runat="server" Text="Label"></asp:Label><br/>
 ??????????????????? <asp:Label ID="LastWriteTimeLabel" runat="server" Text="Label"></asp:Label><br/>
 ??????????????????? <asp:Label ID="AttributesLabel" runat="server" Text="Label"></asp:Label>
 ??????????????? </td>
 ??????????? </tr>
 ??????????? <tr>
 ??????????????? <td align="center" colspan="2">
 ???????????????????  <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="確定" /></td>
 ??????????? </tr>
 ??????? </table>
using System.IO;
public partial class FileInfo : System.Web.UI.Page
 {
 ??? protected void Page_Load(object sender, EventArgs e)
 ??? {
??? }
?? 
 ??? protected void Button1_Click(object sender, EventArgs e)
 ??? {
 ??????? try
 ??????? {
 ??????????? System.IO.FileInfo fi1 = new System.IO.FileInfo(FileNameTextBox.Text);
 ??????????? if (!fi1.Exists)
 ??????????? {
 ??????????????? MsgLabel.Text = "該文件不存在!";
 ??????????????? DirLabel.Visible = false;
 ??????????????? LengthLabel.Visible = false;
 ??????????????? CreationTimeLabel.Visible = false;
 ??????????????? LastWriteTimeLabel.Visible = false;
 ??????????????? AttributesLabel.Visible = false;
 ??????????? }
 ??????????? else
 ??????????? {
 ??????????????? MsgLabel.Text = "獲取文件信息成功!內容如下:";
 ??????????????? DirLabel.Visible = true;
 ??????????????? LengthLabel.Visible = true;
 ??????????????? CreationTimeLabel.Visible = true;
 ??????????????? LastWriteTimeLabel.Visible = true;
 ??????????????? AttributesLabel.Visible = true;
 ??????????????? DirLabel.Text = "文件所在位置:" + fi1.DirectoryName;
 ??????????????? LengthLabel.Text = "文件大小:" + fi1.Length + "字節";
 ??????????????? CreationTimeLabel.Text = "文件創建時間:" + fi1.CreationTime;
??????????????? LastWriteTimeLabel.Text = "文件最近修改時間:" + fi1.LastWriteTime;
??????????????? AttributesLabel.Text = "文件屬性:" + fi1.Attributes;
 ??????????? }
 ??????? }
 ??????? catch (Exception ee)
 ??????? {
 ??????????? MsgLabel.Text = "獲取文件信息失敗!失敗原因:" + ee.ToString();
 ??????? }
 ??? }
 }
轉載于:https://www.cnblogs.com/burandanxin/archive/2008/06/19/1225995.html
總結
以上是生活随笔為你收集整理的文件的删除和文件信息的读取的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 梦到别的孕妇流血什么预兆
- 下一篇: [转载]vs2008下安装boost
