C# how to check and display the content of a folder.

How to scan the content of the folder and listed in textbox

Page 1 of 1

4 Replies - 5881 Views - Last Post: 16 September 2009 - 03:35 AM Rate Topic: -----

#1 dunk_6  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 43
  • Joined: 03-August 09

C# how to check and display the content of a folder.

Posted 15 September 2009 - 11:57 PM

Hi all,

I'm not sure wether this topics has been disscussed before or not, but im not sure the exact word to search for it. What method/class should i used?? Any references/solution are very thankful. Thank you very much.

The program has 3 button: 1) for folder browsing, 2) scan for the selected folder content, and 3) open the file. When user browse the selected folder(1), user click scan button to scan from the first file until the last available files and listed it text box(2) and from that user can decide whether to open the files or not(3).

Here are what have i done so far..(no 1 & 3 ):
//for browse
private void browse2()
		{
			string strPath;
			string strCaption = "Select a Directory and folder.";
			DialogResult dlgResult;
			Shell32.ShellClass shl = new Shell32.ShellClass();
			Shell32.Folder2 fld = (Shell32.Folder2)shl.BrowseForFolder(0, strCaption, 0,
						System.Reflection.Missing.Value);
			if (fld == null)
			{
				dlgResult = DialogResult.Cancel;
			}
			else
			{
				strPath = fld.Self.Path;
				dlgResult = DialogResult.OK;
				this.txtDest.Text = strPath.ToString();
			}
		}
//for open folder
 private void btnOpen_Click(object sender, EventArgs e)
		{
			try
			{
				Process.Start(txtDest.Text);
			}
			catch
			{
				MessageBox.Show("Please select one file/folder");
			}
		}




Is This A Good Question/Topic? 0
  • +

Replies To: C# how to check and display the content of a folder.

#2 janne_panne  Icon User is offline

  • WinRT Dev
  • member icon

Reputation: 428
  • View blog
  • Posts: 1,047
  • Joined: 09-June 09

Re: C# how to check and display the content of a folder.

Posted 16 September 2009 - 12:05 AM

Here are some tips:

1. Allow the user to choose a folder using the System.Windows.Forms.FolderBrowserDialog class

2. Scan the folder using System.IO.Directory.GetFiles() method

3. Open the file using Process.Start() method or if it's a textfile and you want to open it inside your program, use FileStream class.
Was This Post Helpful? 1
  • +
  • -

#3 wyj_China  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 3
  • Joined: 15-September 09

Re: C# how to check and display the content of a folder.

Posted 16 September 2009 - 12:21 AM

using System.IO;

private void button1_Click(object sender, System.EventArgs e)
{//Check
this.folderBrowserDialog1.ShowDialog();
if(this.folderBrowserDialog1.SelectedPath.Trim()!="")
this.textBox1.Text=this.folderBrowserDialog1.SelectedPath.Trim();
}

private void button2_Click(object sender, System.EventArgs e)
{//display
if(this.textBox1.Text.Trim()=="")
return;
this.listBox1.Items.Clear();
string[] MyFiles=Directory.GetFiles(this.textBox1.Text);
this.listBox1.Items.AddRange(MyFiles);
}
Was This Post Helpful? 1
  • +
  • -

#4 dunk_6  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 43
  • Joined: 03-August 09

Re: C# how to check and display the content of a folder.

Posted 16 September 2009 - 01:52 AM

View Postjanne_panne, on 15 Sep, 2009 - 11:05 PM, said:

Here are some tips:

1. Allow the user to choose a folder using the System.Windows.Forms.FolderBrowserDialog class

2. Scan the folder using System.IO.Directory.GetFiles() method

3. Open the file using Process.Start() method or if it's a textfile and you want to open it inside your program, use FileStream class.


Quote

using System.IO.Directory.GetFiles() method


I'm doing winForm.. i thought System.IO is for console application? Both can be used?

Thank you
Was This Post Helpful? 0
  • +
  • -

#5 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1533
  • View blog
  • Posts: 5,972
  • Joined: 21-March 08

Re: C# how to check and display the content of a folder.

Posted 16 September 2009 - 03:35 AM

The System.IO namespace has plenty of classes tht can be use by both console and windows forms apps. I don't think there is one namespace in .Net that is exclusive to one type of application.

So never think that the type of application you are doing will limit the namespaces you can use because it doesn't.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1