views:

76

answers:

3

To aid navigation we would prefer our users to only create pages that have a title of less than or equal to 30 characters. Is there a relatively easy way that this can be accomplished? I've seen a javascript solution that uses a method called PreSaveAction but it's not really what I'm looking for as it has got to work site wide (whether they're in the site settings or in the front end gui using the ribbon).

We are currently deploying our content types via a feature in visual studio if that helps.

edit: in addition this should also limit the length of the url too right? For example we would prefer our users to not create very-long-page-names-that-are-not-user-friendly-etc-etc-etc-etc-etc.aspx

+2  A: 

I think your best bet is to implement a list item event receiver. You can tap into the ItemAdding, ItemUpdating, and ItemFileMoving events to either sanitize the URL to a shorter length, or throw an error. The item event receiver is foolproof, as it runs on the server regardless of the client, be it Office, Windows Explorer, SOAP, or the Web UI.

A receiver can be associated with a content type or individual lists. If you associate with a content type, and you choose Item as your content type, then voila, it's universal. If you want to force it across all sites and site collections, take a look at feature staplers. The idea is that you activate your event receiver feature on all your existing sites, and the stapler feature will activate it for you on all future sites. If you make the feature a hidden feature, your users won't be able to turn it off.

If you really want to go all out, you could customize the forms used to create new pages with a little javascript validation, or just a MaxLength on the text box; however, I prefer to avoid customizing system files.

Good luck!

kbrimington
+1  A: 

Best thing you could do is to Change the File That creates Page, this is SharePoint 2007 trick but it will work for 2010 as well. Page that pops up when you say new page is /_layouts/CreatePublishingPageDialog.aspx make a copy of this page & call it /_layouts/CreatePublishingPageDialog_new.aspx or whatever you want. In the new page add your validation so that you can limit the title to be of 30 Char. Still you can hook the eventhandler of the Button click & limit the Page URL to be of less length.

Now we have a custom page that will do all the validation, next step is to open this page instead of orginal page. You can achive this using steps in this article. Please note you need to edit the file SiteAction.xml article talks about page editing toolbar but you do the same thing to siteaction as well.full copy of this file is present in C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\EditingMenu\SiteAction.xml

Edit:This link has reference on how to do customization to CreatePage.aspx (MOSS)

Kusek
A: 

I think I may have found my own elegant answer that doesn't require any code :) I am able to put validation on the Pages library by going to the Pages library settings > Validation Settings. If I use this in my formula field =LEN(Title)<=30 it does exactly what I want it to do.

However there is still some weird behaviour with the add page dialog though where it shows an error but still creates the page in draft :/ I'll have to look in to that.

soniiic
Ah it doesn't work very elegantly at all! I get a "Save Conflict" dialog box when I'm editing the page content with a title of more than 30 characters and I still can't get it to limit the filename to less than 30 characters either.Also, the validation explanation is never shown to the user unless they are using the "edit properties" dialog box.
soniiic