Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 8th, 2007, 03:07 AM
Registered User
 
Join Date: Feb 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default filtering files while displaying in list box

how to display files of a particular extension in a list box after getting the source directory from which the files of our particular files have to be displayed ?

eg. showing only .java files from c:\\andy

 
Old March 8th, 2007, 02:04 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

There are numerous ways to approact this.
Here is a very simple example to get you started:

Code:
private void cmdDisplay_Click(object sender, System.EventArgs e)
{
    cboFiles.Items.Clear();
    string[] files = Directory.GetFiles("C:\\", "*.txt");
    foreach(string s in files)
    {
        cboFiles.Items.Add(s);    
    }
}
This code just gets and displays the ".txt" files in the C: directory. The Directory.GetFiles method is a static method so you do not instantiate a Directory object.

There are more powerful and better ways to do this, but this should get you started.

Woody Z
http://www.learntoprogramnow.com
How to use a forum to help solve problems





Similar Threads
Thread Thread Starter Forum Replies Last Post
Filtering the list between the date range sea_aiko SharePoint Development 1 August 7th, 2008 04:21 PM
multi-column list box values moved to 2nd list box sbmvr Access VBA 1 May 14th, 2007 01:58 PM
filtering files while displaying in list box anandthecoolest C# 2005 0 March 8th, 2007 03:21 AM
Pre-filtering a selection list asearle XSLT 4 November 7th, 2006 09:24 AM
filtering data from a database using list box europhreak Dreamweaver (all versions) 4 September 25th, 2005 04:27 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.