亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

C#獲得文件屬性信息的實(shí)現(xiàn)方法

 更新時(shí)間:2014年07月29日 10:04:21   投稿:shichen2014  
這篇文章主要介紹了C#獲得文件屬性信息的實(shí)現(xiàn)方法,對(duì)于C#初學(xué)者了解與學(xué)習(xí)應(yīng)用程序設(shè)計(jì)有一定的借鑒價(jià)值,需要的朋友可以參考下

本文實(shí)例演示了用Visual C#獲取任意文件的屬性信息,這些屬性信息包括文件名、創(chuàng)建時(shí)間、訪問時(shí)間、最后寫入時(shí)間等等。本實(shí)例需要用到 FileInfo 類。 FileInfo 類用于提供創(chuàng)建、復(fù)制、刪除、移動(dòng)和打開文件的實(shí)例方法,并且?guī)椭鷦?chuàng)建 FileStream 對(duì)象。

主要功能代碼如下:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
namespace 獲取文件屬性
{
 public class Form1 : System.Windows.Forms.Form
 {
 private System.Windows.Forms.ListBox listBox1;
 private System.Windows.Forms.Button button1;
 private System.Windows.Forms.OpenFileDialog openFileDialog1;
 private System.ComponentModel.Container components = null;
 public void AddItem(string sItem)
 {
  listBox1.Items.Add(sItem); // 添加項(xiàng) sItem 到 listBox1 中
 }
 public Form1()
 {
  InitializeComponent();
 }
 protected override void Dispose( bool disposing )
 {
  if( disposing )
  {
  if (components != null)
  {
   components.Dispose();
  }
  }
  base.Dispose( disposing );
 }
 #region Windows 窗體設(shè)計(jì)器生成的代碼
 private void InitializeComponent()
 {
  this.listBox1 = new System.Windows.Forms.ListBox();
  this.button1 = new System.Windows.Forms.Button();
  this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
  this.SuspendLayout();
  // listBox1
  this.listBox1.ItemHeight = 12;
  this.listBox1.Location = new System.Drawing.Point(8, 56);
  this.listBox1.Name = "listBox1";
  this.listBox1.Size = new System.Drawing.Size(272, 208);
  this.listBox1.TabIndex = 0;
  // button1
  this.button1.Location = new System.Drawing.Point(96, 8);
  this.button1.Name = "button1";
  this.button1.Size = new System.Drawing.Size(96, 32);
  this.button1.TabIndex = 1;
  this.button1.Text = "請(qǐng)選擇文件";
  this.button1.Click += new System.EventHandler(this.button1_Click);
  // Form1
  this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  this.ClientSize = new System.Drawing.Size(292, 273);
  this.Controls.Add(this.button1);
  this.Controls.Add(this.listBox1);
  this.Name = "Form1";
  this.Text = "獲取文件屬性";
  this.ResumeLayout(false);
 }
 #endregion
 [STAThread]
 static void Main()
 {
  Application.Run(new Form1());
 }
 private void button1_Click(object sender, System.EventArgs e)
 {
  if(this.openFileDialog1.ShowDialog() == DialogResult.OK)
  {
  // 清除 listBox1 中所有的項(xiàng)
  listBox1.Items.Clear();
  FileInfo file = new FileInfo(this.openFileDialog1.FileName);
  // 向 ListBox 中一次添加一個(gè)項(xiàng),通過防止該控件繪圖來維護(hù)性能,
  // 直到調(diào)用 EndUpdate 方法為止
  listBox1.BeginUpdate();
  // 獲取文件名
  AddItem("文件名 : " + file.Name);
  // 獲取文件的長度
  AddItem("文件長度(bytes) : " + file.Length);
  // 獲取當(dāng)前 FileSystemInfo 對(duì)象的創(chuàng)建時(shí)間
  AddItem("創(chuàng)建時(shí)間 : " + file.CreationTime.ToString());
  // 獲取上次訪問當(dāng)前文件或目錄的時(shí)間
  AddItem("最后訪問時(shí)間 : " + file.LastAccessTime.ToString());
  // 獲取上次寫入當(dāng)前文件或目錄的時(shí)間
  AddItem("最后寫入時(shí)間 : " + file.LastWriteTime.ToString());
  listBox1.EndUpdate();
  }
 }
 }
}

本例演示了功能代碼的主體部分,讀者可以根據(jù)自己的要求進(jìn)一步完善其窗體界面與功能。

相關(guān)文章

  • C#實(shí)現(xiàn)利用Windows API讀寫INI文件的方法

    C#實(shí)現(xiàn)利用Windows API讀寫INI文件的方法

    這篇文章主要介紹了C#實(shí)現(xiàn)利用Windows API讀寫INI文件的方法,涉及C#針對(duì)ini文件的創(chuàng)建、讀取及寫入等操作技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-07-07
  • C#圖像偽彩色處理方法

    C#圖像偽彩色處理方法

    這篇文章主要介紹了C#圖像偽彩色處理方法,涉及C#操作圖像的偽彩色相關(guān)技巧,需要的朋友可以參考下
    2015-04-04
  • C#定時(shí)器實(shí)現(xiàn)自動(dòng)執(zhí)行的方法

    C#定時(shí)器實(shí)現(xiàn)自動(dòng)執(zhí)行的方法

    這篇文章主要介紹了C#定時(shí)器實(shí)現(xiàn)自動(dòng)執(zhí)行的方法,實(shí)例分析了C#定時(shí)器參數(shù)的設(shè)置及方法的調(diào)用與實(shí)現(xiàn),需要的朋友可以參考下
    2015-01-01
  • C#適用于like語句的SQL格式化函數(shù)

    C#適用于like語句的SQL格式化函數(shù)

    這篇文章主要介紹了C#適用于like語句的SQL格式化函數(shù),可實(shí)現(xiàn)對(duì)字符串進(jìn)行sql格式化,并且符合like查詢的格式,非常實(shí)用,需要的朋友可以參考下
    2014-10-10
  • 淺談c# 泛型類的應(yīng)用

    淺談c# 泛型類的應(yīng)用

    本篇文章是對(duì)c#中泛型類的應(yīng)用進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-05-05
  • c#多線程之線程基礎(chǔ)

    c#多線程之線程基礎(chǔ)

    本文詳細(xì)講解了c#多線程之線程基礎(chǔ),文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-04-04
  • C# 輸出字符串到文本文件中的實(shí)現(xiàn)代碼

    C# 輸出字符串到文本文件中的實(shí)現(xiàn)代碼

    本文通過一個(gè)簡單的代碼給大家介紹C# 輸出字符串到文本文件中,代碼簡單易懂,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友參考下吧
    2018-05-05
  • C#實(shí)現(xiàn)將日期格式化為指定格式

    C#實(shí)現(xiàn)將日期格式化為指定格式

    這篇文章主要為大家詳細(xì)介紹了C#如何使用DateTime.Now.ToString方法將日期格式化為指定格式,文中的示例代碼講解詳細(xì),有需要的小伙伴可以參考下
    2024-01-01
  • OpenXml合并Table單元格代碼實(shí)例

    OpenXml合并Table單元格代碼實(shí)例

    在本篇文章里小編給大家整理了關(guān)于OpenXml合并Table單元格的相關(guān)實(shí)例詳解,需要的朋友們參考下。
    2019-08-08
  • C#如何通過QQ郵件發(fā)送驗(yàn)證碼到指定郵箱

    C#如何通過QQ郵件發(fā)送驗(yàn)證碼到指定郵箱

    在程序設(shè)計(jì)中發(fā)送驗(yàn)證碼是常見的一個(gè)功能,用戶在注冊(cè)賬號(hào)時(shí)或忘記密碼后通常需要發(fā)送驗(yàn)證碼到手機(jī)短信或郵箱來驗(yàn)證身份,這篇文章主要給大家介紹了關(guān)于C#如何通過QQ郵件發(fā)送驗(yàn)證碼到指定郵箱的相關(guān)資料,需要的朋友可以參考下
    2024-01-01

最新評(píng)論