Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello friends,

I have a scenario that I have to give the end user the ability to select a folder in treeview and onclick on folder all of the files and folders inside this will be shown in listview except some specific file type with extension .cab, .mp3 etc..

I am able to show all files but unable to omit the specific file types.

Help me to do this....

Thanx in advance..
Posted

1 solution

Hi
I don't know how you are reading the file list from the folder.
But what I can say that before putting the file list in List view, you can check the file
extension. or you can use the search Pattern of System.IO.Directory.GetFiles
 
Share this answer
 
Comments
abhishekagrwl25 13-May-13 5:50am    
hi tanvir,

I can use System.IO.Directory.GetFiles to select specific file types but here i want to omit the specific file types. that is the problem. Do you have any solution regarding that..??
TanvirRaihan 13-May-13 6:28am    
As far as I know, there is no direct process but you can use lambda expression like:
Directory.GetFiles("path").Where(x => !x.EndsWith(".mp3")).

Or you can read all files and check the file extension in a foreach loop before adding them to ListView.
abhishekagrwl25 13-May-13 6:39am    
foreach (FileInfo file in nodeDirInfo.GetFiles())

this is the foreach loop i am using...
how to use your logic with this..??
TanvirRaihan 13-May-13 6:45am    
foreach (FileInfo file in nodeDirInfo.GetFiles())
{
if (file.Extension.ToLower() != ".mp3" || file.Extension.ToLower() != ".cab")
{
// Put it to list view.
}
}
abhishekagrwl25 13-May-13 6:49am    
but i have to use string array for checking list...because i am dynamically storing values in string array..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900