Click here to Skip to main content
12,694,121 members (34,766 online)
Rate this:
Please Sign up or sign in to vote.
See more: C#
how I can write C# code to sort all the files in my PC according to thier types and show all of them in treeview
Posted 12-Nov-12 4:03am
joshrduncan2012 12-Nov-12 9:24am
What have you tried so far?
ryanb31 12-Nov-12 10:05am
There are many ways to do this. Basically you'll have to traverse the file system and add to treeview. What have you done and where are you stuck?
Nelek 12-Nov-12 10:36am
Sergey Alexandrovich Kryukov 12-Nov-12 14:52pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

If you look at Directory.GetFiles, you will find it has an overload which returns all files in subdirectories as well as the specified folder.
string[] files = Directory.GetFiles(path, "*.*", SearchOption.AllDirectories);

It would then be pretty simple to sort them using Linq methods:
var sorted = files.OrderBy(s => new FileInfo(s).Extension);

Then all you have to do is display them in whatever way your feel like!

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170118.1 | Last Updated 12 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100