Friday 26 April 2013

How to make the 'Description' field mandatory for SharePoint 2010 site creation - Part 2

Part 1 of this post can be found here 

In part 1 I demonstrated how I created a new version of newsbweb.aspx and added validation to this page to ensure that sites created with this form had the description field completed. However, the next part of this problem is to ensure that this form is used for every new site created. 

The first thing I had to do was determine how many different ways there are to create a site using the UI. From my count, there are no less than four. They are listed below:

  1. Site Actions, New Site (This opens the silverlight dialog box)
  2. Site Actions, More Options (Same as above)
  3. A SharePoint application page called create.aspx (this is the html alternative to the silverlight control, and it references newsbweb.aspx)
  4. Site Actions, View All Site Content (a button on this page opens the Silverlight dialog)
  5. Site Settings, Sites and Workspaces (a button on this page opens newsbweb.aspx)
The first three are all in the same place, the Site Actions menu, which can be modified directly on your master page. You can do this through a feature using customactions (hide the old one and create a new one) as well, but I chose to modify the master page directly as it is simpler. I will go through closing off each site creation one by one.

1. 

To modify the Site Actions menu on the master page, look for the section that defines the Site Actions <SharePoint:SiteActions> and within that you will find an entry for each site action tagged by <SharePoint:MenuItemTemplate>. If you look at the MenuItemTemplate with ID MenuItem_CreateSite, you will see that there is an attribute called ClientOnClickScriptContainingPrefixedUrl. I don't know who named that attribute but they deserve an award. remove this attribute and replace it with ClientOnClickNavigateUrl="~site/_layouts/newsbweb2.aspx" to point it to your new page.

2. and 3. 

Find the MenuItemTemplate with ID MenuItem_Create and remove the attribute mentioned above and replace it with ClientOnClickNavigateUrl="~site/_layouts/create2.aspx"  You now need to create a copy of create.aspx (sigh) which will eventually go in your layouts folder. All you need to do in this copied version is replace any reference of newsbweb.aspx to newsbweb2.aspx of which there are a few.


4.

Find the MenuItemTemplate with ID MenuItem_ViewAllSiteContents and change the value of the ClientOnClickNavigateUrl to "~site/_layouts/viewlsts2.aspx". Yes, again you will need to copy your viewlsts.aspx page and create a new version. In this version you will need to hide the "Create" button using css.


<style>
#ctl00_PlaceHolderMain_ToolBar_RptControls_diidIONewList {display:none;}
</style>

You then need to find the <SharePoint:SPLinkButton> with ID diidIONewList and insert a new SPLinkButton after it to recreate the same effect.

<SharePoint:SPLinkButton ID="SPLinkButton1" runat="server" NavigateUrl="~site/_layouts/create2.aspx" text="Create" ImageUrl="/_layouts/images/createcontent.gif" ShowImageAndText="true" HoverCellActiveCssClass="ms-buttonactivehover" HoverCellInActiveCssClass="ms-buttoninactivehover" />

Notice the new button points to create2.aspx and this button looks and behaves exactly the same as the old one, so nobody is the wiser.

5.

I saved the best for last... As you probably predicted, you will need to create a copied version of the Sites and Workspaces application page mngsubwebs.aspx and modify it to point to your new page. You can do this by finding the create button and changing the NavigateUrl value, shown below.

<wssuc:ToolBarButton runat="server" id="newsite"
ImageUrl="/_layouts/images/newitem.gif"
ToolTip="<%$Resources:wss,multipages_createbutton_text%>"
Text="<%$Resources:wss,multipages_createbutton_text%>"
NavigateUrl="cw-newsbweb.aspx"
accesskey="N"/>

Now, this page is accessed through site settings, and you can create a new version of site settings page (settings.aspx) and update your master page if you want to, but the client site already uses a feature that hides certain options from the site settings page and recreates them if the user is an administrator. So all I did was repeat this for the Sites and Workspaces setting and when recreating it, made sure that it pointed to the mngsubwebs2.aspx page. Information can be found all over the web about how to use customactions to hide items from this page so I won't document that here.

So, that's me done and as far as I can see, there are now no ways to create sites on this site collection without entering a description. I know, it was a tedious and cumbersome, and messy process... but the client preferred this solution and I agree with them. There is no point in the event receiver solution as it will simply annoy users.

Finally, as I said in Part 1, you would be better to not add these new application pages to your 14 hive manually. Instead, create a new VS2010 project, map a folder to your layouts folder, and add these application pages here. That way when you deploy the solution the files will be added on all front end server automatically and removed when you retract the solution.

I hope this has been helpful/informative for someone. Please leave comments or let me know if you have a better way!

Tal

No comments:

Post a Comment