Wednesday, June 28, 2006

What's new webpart UPDATED!

Updated again? Yes again! Why you wonder.. well an user commented me about the fact that documents that are stored in folders (in a document library) didn't show up on the webpart. So therefore I have updated the source of Jan's great webpart (again). Here's the function that get's all the items from the current site and all it's subsites.

private ArrayList GetSubwebs(SPWeb web) { System.Collections.Hashtable listFieldsHashTable = GetListFieldHashTable(); System.Collections.Hashtable excludeListsHashTable = GetExcludeListsHashTable(); System.Collections.ArrayList items = new System.Collections.ArrayList(); web.Lists.IncludeRootFolder = true; foreach(SPList list in web.Lists) { if(list.Permissions.DoesUserHavePermissions(SPRights.ViewListItems)) { if(!excludeListsHashTable.ContainsKey(list.Title)) { SPQuery query = new SPQuery(); query.Query = ""; query.RowLimit = (uint)this.ItemsToDisplay; foreach(SPListItem listItem in list.GetItems(query)) { items.Add(listItem); } if (list.RootFolder.SubFolders.Count > 1) { foreach(SPFolder folder in list.RootFolder.SubFolders) { //In case of a Workspace template there is always a "1" folder if (folder.Name == "1") { foreach(SPFolder subfolder in folder.SubFolders) { items.AddRange(GetSubFolder(subfolder, list)); } } else { items.AddRange(GetSubFolder(folder, list)); } } } } } } foreach (SPWeb subweb in web.Webs) { items.AddRange(GetSubwebs(subweb)); subweb.Dispose(); } return items; }
And here is the (recursive) function that fetches all the items from folders:
private ArrayList GetSubFolder(SPFolder folder, SPList list) { System.Collections.ArrayList items = new System.Collections.ArrayList(); SPQuery subquery = new SPQuery(); subquery.Folder = folder; subquery.Query = ""; subquery.RowLimit = (uint)this.ItemsToDisplay; foreach(SPListItem listItem in list.GetItems(subquery)) { items.Add(listItem); } foreach(SPFolder subfolder in folder.SubFolders) { items.AddRange(GetSubFolder(subfolder, list)); } return items; }
btw.. i'll upload the complete solution soon so you can download it (since blogspot messes up some tags used in the query ;)

4 comments:

Anonymous said...

Could you please upload to some place the complete solution of this webpart and post link where can we download it. Thx!

umang shah said...

hey robin can you please upload your code or email me

public key infrastructure said...

Congratulations, your blog is appealing and informative. Going through your Information, I found quite a few new ideas to implement

Bree Bites said...

Great read, thanks