Tuesday, August 30, 2011

Create URL Redirection upon Event Errors


File->New->Project->SharePoint 2010->Empty Project->CustomErrorPage
CustomErrorPage->Add->New Item->SharePoint 2010->Event Receiver->MaxSubSitesReceiver
EventReceiverType->Web Events
Handle Events When->site is being provisioned
//MaxSubSitesReceiver->MaxSubSitesReceiver.cs
using System;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Security;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.Workflow;

namespace CustomErrorPage.MaxSubSitesReceiver
{  
    public class MaxSubSitesReceiver : SPWebEventReceiver
    {
       public override void WebAdding(SPWebEventProperties properties)
       {
           if (properties.Web.Webs.Count >= 2)
           {
               properties.Status = SPEventReceiverStatus.CancelWithRedirectUrl;
               properties.Cancel = true;
               properties.RedirectUrl = "/_layouts/CustomErrorPage/SiteCreationError.aspx";
           }
       }
    }
}
----------------------------------------------------------------------------------------
CustomErrorPage->Add->SharePoint "Layouts" Mapped Folder
Layouts->CustomErroPage->Add Item->New Item->SharePoint 2010->Application Page->SiteCreationError.aspx

<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SiteCreationError.aspx.cs" Inherits="CustomErrorPage.Layouts.CustomErrorPage.SiteCreationError" DynamicMasterPageFile="~masterurl/default.master" %>
<asp:Content ID="PageHead" ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">
</asp:Content>
<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
<p>
  ERROR: You can only have a maximum of two (2) subsites in the current site.
</p>
</asp:Content>
<asp:Content ID="PageTitle" ContentPlaceHolderID="PlaceHolderPageTitle" runat="server">
  ERROR: Maximum Subsites in Current Site Exceeded
</asp:Content>
<asp:Content ID="PageTitleInTitleArea" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea" runat="server" >
ERROR: Maximum Subsites in Current Site Exceeded
</asp:Content>
 

No comments:

Post a Comment

Featured Post

Azure OpenAI Chat in C# and Python

Azure OpenAI Chat in C#: // Install the .NET library via NuGet: dotnet add package Azure.AI.OpenAI --version 1.0.0-beta.5   using System; u...

Popular posts