In my previous article, I explained developing navigation menu in SharePoint using XML file and dataformwebpart. In this log, I will explain how to generate security trimmed navigation menu. To make things even more complex, there are two types of trimming:
1. Still show the menu item in the navigation, but while users click the menu, a message box should pop up and say "You are not authorized to view the page"
2. Will not show the menu item at all.
The solution is to add another SPDataSource to the DataFormWebPart in addition to the XML data source used to retrieve the XML file. (Notice, you are using AggregateSource here) The new datasource will perform a "CrossList" query to all the Pages libraries in the sitecollection. If the current log-in user does not have permission to view a page, the new datasource should not return any record for the page. So, in XSLT code, we just need to perform a filter not to generate menu item for those pages in XML datasource but not returned from the new datasource.
However, we have not solved the problem completely because, for some trimmed pages, we still need to generate menu item and hook up the java script code to display the pop up message box. The solution is to introduce a new attribute to the nodes in the XML file. For example, we can add a boolean attribute "IsGeneratingMessageIfNoPermmission" . The XSLT code will handle the property accordingly.
Once again, it demonstrates using "XML file + DataFormWebpart" to generate navigation menu for sharepoint is a very extensible approach, which fully takes advantage of the power of XSLT and dataformwebprt.
No comments:
Post a Comment