Thursday, July 30, 2009

One webpart for Intranet, Extranet & Internet

Today, I came across with a scenario "One webpart for Intranet, Extranet & Internet".

Requirement: "The web part supports multiple data sources. All data sources are not common for Intranet, Extranet & Internet versions. Based on the version, we have to show only corresponding data sources."

Example:We have a news web part with following data sources support:
  • news pages from an intranet site which are created with a News content type.
  • current/local site collection which has pages of a particular content type (this content type is similar to News content type but with few more fields additional)
  • RSS Feed - This is generic RSS feed support. So, RSS defined in intranet, extranet or internet sites should be handled in similar manner. Ofcourse, RSS content xml format is not different than general RSS content xml format.
For INTRANET, News web part should show all the above data sources.
For INTERNET & EXTRANET, News web part should show the data sources mentioned in (b) and (c).
NOTE: The configuration should be hidden from end user who can see web part toolpane.

Solution:
Step1: Add a property in newswebpart.webpart file (this is an xml file) under ///
Step2: Add a browsable property in the web part C# file. Don't forget to set
WebBrowsable(false) for this property. This allows us to hide the configuration for data source support in web part toolpane.

Step3: Include a condition in web part tool pane display data sources based on the value of the property set.

Note: We can implement above in other ways also but I opted above to allow configuration from webpart xml file instead of modifying in the C# code or from web part toolpane.

No comments: