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); // 添加项 sItem 到 listBox1 中
}
public Form1()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
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 = "请选择文件";
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 中所有的项
listBox1.Items.Clear();
FileInfo file = new FileInfo(this.openFileDialog1.FileName);
// 向 ListBox 中一次添加一个项,通过防止该控件绘图来维护性能,
// 直到调用 EndUpdate 方法为止
listBox1.BeginUpdate();
// 获取文件名
AddItem("文件名 : " + file.Name);
// 获取文件的长度
AddItem("文件长度(bytes) : " + file.Length);
// 获取当前 FileSystemInfo 对象的创建时间
AddItem("创建时间 : " + file.CreationTime.ToString());
// 获取上次访问当前文件或目录的时间
AddItem("最后访问时间 : " + file.LastAccessTime.ToString());
// 获取上次写入当前文件或目录的时间
AddItem("最后写入时间 : " + file.LastWriteTime.ToString());
listBox1.EndUpdate();
}
}
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有