Extending CreatePublishingPageDialog Class with a Modified File Already Exists Validation Logic
There a few nasty problem in SharePoint 2010′s default create publishing page dialog. One of the problems is that you cannot specify a file name or that SharePoint doesn’t automatically create a new filename if one with the same title already exists. Juha talked about this problem earlier, and he asked me to define my approach to create a better “create publishing page dialog”.
Well this is a rather easy one… let’s first make a copy of:
I created mine inside (yes, I use WSPs):
CreatePublishingPageDialog.aspx
I modified the Inherits attribute of that page to (I didn’t make any other modifications):
And then I wrote a new file exists validation logic with auto generating file name:
Microsoft.SharePoint.Publishing.
Internal.CodeBehind.CreatePublishingPageDialog
{
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
var web = SPContext.Current.Web;
if (!IsPostBack || web == null ||
!PublishingWeb.IsPublishingWeb(web)) return;
var file = nameInput.Text;
fileExistValidator.Validate();
var i = 1;
while (!fileExistValidator.IsValid)
{
nameInput.Text = string.Format("{0}-{1}", file, ++i);
fileExistValidator.Validate();
}
}
}
We can have this new Create Publishing Page dialog in Site Actions menu by writing a custom action feature, or just adding MenuItemTemplate directly to our masterpage, like I did in below:
runat="server"
id="SharePoint_Accelerator_CreatePublishingPageDialog"
Text="..."
Description="..."
ImageUrl="/_layouts/images/crtpage.gif"
ClientOnClickScriptContainingPrefixedUrl="
if (LaunchCreateHandler('PublishingPage')) {
SP.UI.ModalDialog.OpenPopUpPage(
'~site/_layouts/.../CreatePublishingPageDialog.aspx',
null,
390);
};"
MenuGroupId="200"
Sequence="210"
PermissionContext="CurrentList"
PermissionsString="AddListItems, EditListItems"
PermissionMode="All" />
If you want to see how we can hide the existing Create Page link from Site Actions menu, read this article.
Now what we have done here is that we extended Create Page dialog to never fail even if we use same title as we used for some other page in that page library. You can use your own imagination from here on. You can for example provide a picker to select a page layout in a dialog, or to define a folder inside page library where to create that page.
Popularity: 4% [?]
Great job!
Thanks for this article, and could you please provide me with more details about the code behind that is stated above (where to put this code, sorry but I’m new in sharepoint development)
Hi,
This code will not work if the library you are checking has files checked out with the same name as the file you are creating, you’ll get an exception.
Regards,
Magnus