Order Sharepoint areas like the portal hierarchy

By jpsmit
May 23, 2005
0


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];


       }


}


 


Comments: 0

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Recent Posts
  • Recent Comments
  • Archives
  • Categories
  • Meta