Sort SPFolder in SharePoint

We developed a web part showing the folders hierarchy using tree view control. However the folders were not getting displayed in the tree view node in the order they are visible inside the document library i.e. sorted on name.

Creating a tree view

http://www.davehunter.co.uk/Blog/Lists/Posts/Post.aspx?List=f0e16a1a-6fa9-4130-bcab-baeb97ccc4ff&ID=115

So finally used the following code to sort the folders

List<SPFolder> folderList = new List<SPFolder>();

foreach (SPFolder myFolder in folder.SubFolders){

folderList.Add(myFolder);

}

folderList.Sort(delegate(SPFolder p1, SPFolder p2) { return p1.Name.CompareTo(p2.Name); });

For more information on sorting

http://www.developerfusion.com/code/5513/sorting-and-searching-using-c-lists/

Bye..


Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

4 thoughts on “Sort SPFolder in SharePoint”

Share your thoughts

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s