using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
namespace 文件
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.ListBox listBox2;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label10;
private System.Windows.Forms.TextBox txtBoxInput;
private System.Windows.Forms.Button buttonDisplay;
private System.Windows.Forms.TextBox txtBoxFolder;
private System.Windows.Forms.Button buttonUp;
private System.Windows.Forms.TextBox textBoxFileName;
private System.Windows.Forms.TextBox textBoxFileSize;
private System.Windows.Forms.TextBox textBoxCreatetime;
private System.Windows.Forms.TextBox textBoxLastFication;
private System.Windows.Forms.TextBox textBoxLastTime;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.txtBoxInput = new System.Windows.Forms.TextBox();
this.buttonDisplay = new System.Windows.Forms.Button();
this.txtBoxFolder = new System.Windows.Forms.TextBox();
this.buttonUp = new System.Windows.Forms.Button();
this.listBox1 = new System.Windows.Forms.ListBox();
this.listBox2 = new System.Windows.Forms.ListBox();
this.label4 = new System.Windows.Forms.Label();
this.textBoxFileName = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this.textBoxFileSize = new System.Windows.Forms.TextBox();
this.textBoxCreatetime = new System.Windows.Forms.TextBox();
this.label7 = new System.Windows.Forms.Label();
this.label8 = new System.Windows.Forms.Label();
this.textBoxLastFication = new System.Windows.Forms.TextBox();
this.textBoxLastTime = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label10 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// txtBoxInput
//
this.txtBoxInput.Location = new System.Drawing.Point(24, 48);
this.txtBoxInput.Name = "txtBoxInput";
this.txtBoxInput.Size = new System.Drawing.Size(264, 21);
this.txtBoxInput.TabIndex = 1;
this.txtBoxInput.Text = "";
//
// buttonDisplay
//
this.buttonDisplay.Location = new System.Drawing.Point(336, 48);
this.buttonDisplay.Name = "buttonDisplay";
this.buttonDisplay.TabIndex = 2;
this.buttonDisplay.Text = "Display";
this.buttonDisplay.Click += new System.EventHandler(this.buttonDisplay_Click);
//
// txtBoxFolder
//
this.txtBoxFolder.Location = new System.Drawing.Point(24, 104);
this.txtBoxFolder.Name = "txtBoxFolder";
this.txtBoxFolder.Size = new System.Drawing.Size(264, 21);
this.txtBoxFolder.TabIndex = 4;
this.txtBoxFolder.Text = "";
//
// buttonUp
//
this.buttonUp.Location = new System.Drawing.Point(336, 104);
this.buttonUp.Name = "buttonUp";
this.buttonUp.TabIndex = 5;
this.buttonUp.Text = "Up";
//
// listBox1
//
this.listBox1.ItemHeight = 12;
this.listBox1.Location = new System.Drawing.Point(24, 168);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(152, 112);
this.listBox1.TabIndex = 6;
//
// listBox2
//
this.listBox2.ItemHeight = 12;
this.listBox2.Location = new System.Drawing.Point(192, 168);
this.listBox2.Name = "listBox2";
this.listBox2.Size = new System.Drawing.Size(152, 112);
this.listBox2.TabIndex = 7;
//
// label4
//
this.label4.Location = new System.Drawing.Point(24, 312);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(100, 16);
this.label4.TabIndex = 9;
this.label4.Text = "File Name";
//
// textBoxFileName
//
this.textBoxFileName.Location = new System.Drawing.Point(144, 312);
this.textBoxFileName.Name = "textBoxFileName";
this.textBoxFileName.Size = new System.Drawing.Size(224, 21);
this.textBoxFileName.TabIndex = 10;
this.textBoxFileName.Text = "";
//
// label5
//
this.label5.Location = new System.Drawing.Point(24, 352);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(100, 16);
this.label5.TabIndex = 11;
this.label5.Text = "File Size";
//
// label6
//
this.label6.Location = new System.Drawing.Point(200, 352);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(100, 16);
this.label6.TabIndex = 12;
this.label6.Text = "Creation time";
//
// textBoxFileSize
//
this.textBoxFileSize.Location = new System.Drawing.Point(24, 384);
this.textBoxFileSize.Name = "textBoxFileSize";
this.textBoxFileSize.Size = new System.Drawing.Size(128, 21);
this.textBoxFileSize.TabIndex = 13;
this.textBoxFileSize.Text = "";
//
// textBoxCreatetime
//
this.textBoxCreatetime.Location = new System.Drawing.Point(200, 384);
this.textBoxCreatetime.Name = "textBoxCreatetime";
this.textBoxCreatetime.Size = new System.Drawing.Size(152, 21);
this.textBoxCreatetime.TabIndex = 14;
this.textBoxCreatetime.Text = "";
//
// label7
//
this.label7.Location = new System.Drawing.Point(24, 416);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(112, 16);
this.label7.TabIndex = 15;
this.label7.Text = "Last modification time";
//
// label8
//
this.label8.Location = new System.Drawing.Point(200, 416);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(112, 16);
this.label8.TabIndex = 16;
this.label8.Text = "Last access time";
//
// textBoxLastFication
//
this.textBoxLastFication.Location = new System.Drawing.Point(24, 440);
this.textBoxLastFication.Name = "textBoxLastFication";
this.textBoxLastFication.Size = new System.Drawing.Size(128, 21);
this.textBoxLastFication.TabIndex = 17;
this.textBoxLastFication.Text = "";
//
// textBoxLastTime
//
this.textBoxLastTime.Location = new System.Drawing.Point(200, 440);
this.textBoxLastTime.Name = "textBoxLastTime";
this.textBoxLastTime.Size = new System.Drawing.Size(152, 21);
this.textBoxLastTime.TabIndex = 18;
this.textBoxLastTime.Text = "";
//
// label1
//
this.label1.Location = new System.Drawing.Point(32, 136);
this.label1.Name = "label1";
this.label1.TabIndex = 20;
this.label1.Text = "File";
//
// label10
//
this.label10.Location = new System.Drawing.Point(192, 136);
this.label10.Name = "label10";
this.label10.TabIndex = 21;
this.label10.Text = "Folders";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(472, 470);
this.Controls.Add(this.label10);
this.Controls.Add(this.label1);
this.Controls.Add(this.textBoxLastTime);
this.Controls.Add(this.textBoxLastFication);
this.Controls.Add(this.label8);
this.Controls.Add(this.label7);
this.Controls.Add(this.textBoxCreatetime);
this.Controls.Add(this.textBoxFileSize);
this.Controls.Add(this.label6);
this.Controls.Add(this.label5);
this.Controls.Add(this.textBoxFileName);
this.Controls.Add(this.label4);
this.Controls.Add(this.listBox2);
this.Controls.Add(this.listBox1);
this.Controls.Add(this.buttonUp);
this.Controls.Add(this.txtBoxFolder);
this.Controls.Add(this.buttonDisplay);
this.Controls.Add(this.txtBoxInput);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
public void ClearAllFields()
{
listBox1.Items.Clear();
listBox2.Items.Clear();
txtBoxInput.Text="";
textBoxFileName.Text="";
textBoxFileSize.Text="";
textBoxCreatetime.Text="";
textBoxLastFication.Text="";
textBoxLastTime.Text="";
}
protected void DisplayFileInfo(string fileFullName)
{
FileInfo thefile=new FileInfo(fileFullName);
if(!thefile.Exists)
throw new FileNotFoundException("File not found:"+fileFullName);
textBoxFileName.Text=thefile.Name;
textBoxCreatetime.Text=thefile.CreationTime.ToLongTimeString();
textBoxLastTime.Text=thefile.LastAccessTime.ToLongDateString();
textBoxLastFication.Text=thefile.LastWriteTime.ToLongDateString();
textBoxFileSize.Text=thefile.Length.ToString()+"bytes";
}
protected void DisplayFoldList(string folderFullName)
{
DirectoryInfo theFolder=new DirectoryInfo(folderFullName);
if(!theFolder.Exists)
throw new DirectoryNotFoundException("Folder not found:"+folderFullName);
ClearAllFields();
txtBoxFolder.Text=theFolder.FullName;
string currentFolderPath=theFolder.FullName;
foreach(DirectoryInfo nextFolder in theFolder.GetDirectories())
listBox2.Items.Add(nextFolder.Name);
foreach(FileInfo nextFile in theFolder.GetFiles())
listBox1.Items.Add(nextFile.Name);
}
private void buttonDisplay_Click(object sender, System.EventArgs e)
{
string folderPath=txtBoxInput.Text;
DirectoryInfo theFolder=new DirectoryInfo(folderPath);
if(theFolder.Exists)
{
DisplayFoldList(theFolder.FullName);
return;
}
FileInfo theFile=new FileInfo(folderPath);
if(theFile.Exists)
{
DisplayFoldList(theFile.Directory.FullName);
int index=listBox1.Items.IndexOf(theFile.FullName);
listBox1.SetSelected(index,true);
return;
}
throw new FileNotFoundException("There is no file or folder with"+"this name:"+txtBoxInput.Text);
}
}
}
又是出现了“出现了未处理的异常”这个东西,我输入C:\Inetpub\iissamples\sdk这么不行啊,帮我看看啊,谢谢。
[此贴子已经被作者于2006-8-2 16:25:22编辑过]