| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1090 人关注过本帖
标题:[求助]查看文件的问题
只看楼主 加入收藏
小妖精ai漂亮
Rank: 1
等 级:新手上路
帖 子:95
专家分:0
注 册:2006-7-21
收藏
 问题点数:0 回复次数:13 
[求助]查看文件的问题

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编辑过]

搜索更多相关主题的帖子: System using Forms 文件 Windows 
2006-08-02 16:05
chenjin145
Rank: 1
等 级:禁止访问
帖 子:3922
专家分:0
注 册:2006-7-12
收藏
得分:0 

太長了
哪里出現異常


[url=javascript:alert(1);] [div]fdgfdgfdg\" on\"[/div] [/url]
2006-08-02 16:13
小妖精ai漂亮
Rank: 1
等 级:新手上路
帖 子:95
专家分:0
注 册:2006-7-21
收藏
得分:0 
System.IO.DirectoryNotFoundException: Folder not found:C:\Inetpub\iissamples\sdk
at 文件.Form1.DisplayFoldList(String folderFullName) in c:\documents and settings\刘小慧\my documents\visual studio projects\文件\form1.cs:line 300
at 文件.Form1.buttonDisplay_Click(Object sender, EventArgs e) in c:\documents and settings\刘小慧\my documents\visual studio projects\文件\form1.cs:line 318
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

别试图教猪唱歌,这样不但教不会,还会惹猪不高兴!
2006-08-02 16:17
chenjin145
Rank: 1
等 级:禁止访问
帖 子:3922
专家分:0
注 册:2006-7-12
收藏
得分:0 
Folder not found:C:\Inetpub\iissamples\sdk

上面寫沒找到這個文件夾阿

[url=javascript:alert(1);] [div]fdgfdgfdg\" on\"[/div] [/url]
2006-08-02 16:20
chenjin145
Rank: 1
等 级:禁止访问
帖 子:3922
专家分:0
注 册:2006-7-12
收藏
得分:0 

昏倒
if(theFolder.Exists)
throw new DirectoryNotFoundException("Folder not found:"+folderFullName);

如果文件存在
拋出文件不存在的異常???


[url=javascript:alert(1);] [div]fdgfdgfdg\" on\"[/div] [/url]
2006-08-02 16:22
小妖精ai漂亮
Rank: 1
等 级:新手上路
帖 子:95
专家分:0
注 册:2006-7-21
收藏
得分:0 
肯定有啊,我直接找到那个文件然后用那个地址的!

别试图教猪唱歌,这样不但教不会,还会惹猪不高兴!
2006-08-02 16:23
noshow
Rank: 2
等 级:新手上路
威 望:4
帖 子:1127
专家分:0
注 册:2006-4-21
收藏
得分:0 

[CODE]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);

}[/CODE]


此号自封于2006年11月30日
2006-08-02 16:24
小妖精ai漂亮
Rank: 1
等 级:新手上路
帖 子:95
专家分:0
注 册:2006-7-21
收藏
得分:0 
我改了

别试图教猪唱歌,这样不但教不会,还会惹猪不高兴!
2006-08-02 16:26
chenjin145
Rank: 1
等 级:禁止访问
帖 子:3922
专家分:0
注 册:2006-7-12
收藏
得分:0 
貼代碼
那些自動生成的就別貼了
進來,乍一看 這麼長 嚇一跳

[url=javascript:alert(1);] [div]fdgfdgfdg\" on\"[/div] [/url]
2006-08-02 16:27
小妖精ai漂亮
Rank: 1
等 级:新手上路
帖 子:95
专家分:0
注 册:2006-7-21
收藏
得分:0 
嘿嘿,好了,看来noshow不是神经病!

别试图教猪唱歌,这样不但教不会,还会惹猪不高兴!
2006-08-02 16:28
快速回复:[求助]查看文件的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.036389 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved