Order Sharepoint areas like the portal hierarchy


A few weeks ago I was working on a web part which had to display the area hierarchy, much like the way topics are displayed.


When implementing I found out that the areas in the AreaCollection were returned in alphabetical order and not in the hiearchical order that Sharepoint uses. It turned out that other people also ran into this. Using the ‘HonorOrder’ property didn’t help a lot and in fact it is unclear what that property actually does.


I built my own AreaCollection, very easy but very useful. One thing to be aware of:  when an area is removed from the collection Sharepoint doesn’t renumber the other areas. This means that you can have 3 areas with order numbers like 2, 5 and 9. This implementation is taking that into account.


int tmpAreaCnt = 0;


int nbrOfVisibleAreas = 0;


 


// Determine the highest order number


foreach(Area thisArea in SomeArea.Areas)


{


       if(thisArea.Order > tmpAreaCnt)


       {


              tmpAreaCnt = thisArea.Order;


       }


}


 


// Create temp and real array objects to contain the sorted areas


// Increase the counter by one, the array is 0-based


tmpAreaCnt++;


Area[] tmpPortalAreaColl = new Area[tmpAreaCnt];


 


foreach(Area thisArea in SomeArea.Areas)


{


       if(thisArea.Navigation == AreaNavigation.Show)


       {


              tmpPortalAreaColl[thisArea.Order] = thisArea;


              nbrOfVisibleAreas++;


       }


}


 


// Now we only have to remove the empty entries


int areaCnt = 0;


Area[] portalAreaColl = new Area[nbrOfVisibleAreas];


for(int i=0; i<tmpAreaCnt; i++)


{


       if(tmpPortalAreaColl[i] != null)


       {


              portalAreaColl[areaCnt++] = tmpPortalAreaColl[i];


       }


}


 


New blogger in town

Last month I received an invitation from LogicaCMG to start a weblog at BloggingAbout.NET. This invitation was based on my visit to the LogicaCMG booth on the Microsoft DevDays 2005 earlier this year. I left my business card there to be able to win something which I didn’t of course. 😉 


The invitation was sent the moment I was looking for another hosting party for my blog which is currently hosted by XS4ALL, so I decided to accept the offer. I would like to thank Dennis and Petra from LogicaCMG for this opportunity.


I work at a company called Macaw. Macaw is a Microsoft Gold Partner in Intranets and e-commerce. I work on a variety of projects with of course .NET and Mircosoft server products like Sharepoint 2003 and Biztalk 2004.


You’ll find postings here in one of these areas most of the time.


Happy reading and please leave your comments if I write something completely stupid 😉