Tuesday, February 3, 2009

Writing application or site collection specific layout page

I am sure this is very common. Often more than one project is customizing sharepoint and they want to restrict their custom layout pages to their particular site collection.

I introduced a check in the page load and accordingly I display the page.

For SetApplicationNameFeatureReceiver.cs :
Read article How to update to property bag using feature.

Code( ApplicationPage.cs):

 public class ApplicationSpecificPage : LayoutsPageBase  {
protected override void OnLoad(EventArgs e) {
try {
// Make sure not to include '/' at the end of URI
string AppName = "MyCustomApplicationName"";

if (AppName != null && SPContext.Current.Web.Properties["AppName"]!= AppName)
SPUtility.TransferToErrorPage("Page does not exist.");

if (!Page.IsPostBack) {
// Do Something
catch( Exception){