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
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!