显示文件信息
1
using System;
2
using System.Drawing;
3
using System.Collections;
4
using System.ComponentModel;
5
using System.Windows.Forms;
6
using System.Data;
7
// 添加新的命名空间。
8
using System.IO;
9![]()
10
namespace FileInfo
11
{
12
/// <summary>
13
/// 显示文件信息。
14
/// </summary>
15
public class Form1 : System.Windows.Forms.Form
16
{
17
private System.Windows.Forms.Button button1;
18
private System.Windows.Forms.TextBox textBox1;
19
private System.Windows.Forms.Label label1;
20
private System.Windows.Forms.ListView listView1;
21
private System.Windows.Forms.OpenFileDialog openFileDialog1;
22
/// <summary>
23
/// 必需的设计器变量。
24
/// </summary>
25
private System.ComponentModel.Container components = null;
26![]()
27
public Form1()
28
{
29
//
30
// Windows 窗体设计器支持所必需的
31
//
32
InitializeComponent();
33![]()
34
//
35
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
36
//
37
}
38![]()
39
/// <summary>
40
/// 清理所有正在使用的资源。
41
/// </summary>
42
protected override void Dispose( bool disposing )
43
{
44
if( disposing )
45
{
46
if (components != null)
47
{
48
components.Dispose();
49
}
50
}
51
base.Dispose( disposing );
52
}
53![]()
54
Windows Form Designer generated code
120![]()
121
/// <summary>
122
/// 应用程序的主入口点。
123
/// </summary>
124
[STAThread]
125
static void Main()
126
{
127
Application.Run(new Form1());
128
}
129
// 显示文件信息。
130
private void button1_Click(object sender, System.EventArgs e)
131
{
132
if(openFileDialog1.ShowDialog() == DialogResult.OK)
133
{
134
textBox1.Text = openFileDialog1.FileName;
135
System.IO.FileInfo file = new System.IO.FileInfo(openFileDialog1.FileName);
136
listView1.Clear();
137
listView1.Columns.Add("文件名", 100, HorizontalAlignment.Left);
138
listView1.Columns.Add("大小", 100, HorizontalAlignment.Left);
139
listView1.Columns.Add("最后访问时间", 100, HorizontalAlignment.Left);
140
listView1.Columns.Add("最后修改时间", 100, HorizontalAlignment.Left);
141
listView1.Columns.Add("路径", 200, HorizontalAlignment.Left);
142
string[] str =
143
{
144
file.Name,
145
file.Length.ToString(),
146
file.LastAccessTime.ToString(),
147
file.LastWriteTime.ToString(),
148
file.DirectoryName
149
};
150
ListViewItem item = new ListViewItem(str);
151
listView1.Items.Add(item);
152
}
153
}
154
}
155
}
156![]()
using System;2
using System.Drawing;3
using System.Collections;4
using System.ComponentModel;5
using System.Windows.Forms;6
using System.Data;7
// 添加新的命名空间。8
using System.IO;9

10
namespace FileInfo11
{12
/// <summary>13
/// 显示文件信息。14
/// </summary>15
public class Form1 : System.Windows.Forms.Form16
{17
private System.Windows.Forms.Button button1;18
private System.Windows.Forms.TextBox textBox1;19
private System.Windows.Forms.Label label1;20
private System.Windows.Forms.ListView listView1;21
private System.Windows.Forms.OpenFileDialog openFileDialog1;22
/// <summary>23
/// 必需的设计器变量。24
/// </summary>25
private System.ComponentModel.Container components = null;26

27
public Form1()28
{29
//30
// Windows 窗体设计器支持所必需的31
//32
InitializeComponent();33

34
//35
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码36
//37
}38

39
/// <summary>40
/// 清理所有正在使用的资源。41
/// </summary>42
protected override void Dispose( bool disposing )43
{44
if( disposing )45
{46
if (components != null) 47
{48
components.Dispose();49
}50
}51
base.Dispose( disposing );52
}53

54
Windows Form Designer generated code120

121
/// <summary>122
/// 应用程序的主入口点。123
/// </summary>124
[STAThread]125
static void Main() 126
{127
Application.Run(new Form1());128
}129
// 显示文件信息。130
private void button1_Click(object sender, System.EventArgs e)131
{132
if(openFileDialog1.ShowDialog() == DialogResult.OK)133
{134
textBox1.Text = openFileDialog1.FileName;135
System.IO.FileInfo file = new System.IO.FileInfo(openFileDialog1.FileName);136
listView1.Clear();137
listView1.Columns.Add("文件名", 100, HorizontalAlignment.Left);138
listView1.Columns.Add("大小", 100, HorizontalAlignment.Left);139
listView1.Columns.Add("最后访问时间", 100, HorizontalAlignment.Left);140
listView1.Columns.Add("最后修改时间", 100, HorizontalAlignment.Left);141
listView1.Columns.Add("路径", 200, HorizontalAlignment.Left);142
string[] str =143
{144
file.Name,145
file.Length.ToString(),146
file.LastAccessTime.ToString(),147
file.LastWriteTime.ToString(),148
file.DirectoryName149
};150
ListViewItem item = new ListViewItem(str);151
listView1.Items.Add(item);152
}153
}154
}155
}156



浙公网安备 33010602011771号