Extending CreatePublishingPageDialog Class with a Modified File Already Exists Validation Logic

August 23 2010 19 comments

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:

14\TEMPLATE\LAYOUTS\CreatePublishingPageDialog.aspx

I created mine inside (yes, I use WSPs):

14\TEMPLATE\LAYOUTS\SharePoint.Accelerator.Web.UI\
   CreatePublishingPageDialog.aspx

I modified the Inherits attribute of that page to (I didn’t make any other modifications):

Inherits="SharePoint.Accelerator.Web.UI.CreatePublishingPageDialog, ..."

And then I wrote a new file exists validation logic with auto generating file name:

public class CreatePublishingPageDialog :
  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:

<SharePoint:MenuItemTemplate
   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: 2% [?]

19 comments to “Extending CreatePublishingPageDialog Class with a Modified File Already Exists Validation Logic”

  1. Juha Pitkänen says:

    Great job!

  2. Samer Qarajai says:

    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)

  3. Magnus F says:

    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

  4. Jan Lange says:

    Cool, just what I was looking for, thanks !

  5. find it says:

    fantastic publish, very informative. I ponder why the opposite specialists of this sector don’t realize this. You must continue your writing. I am sure, you’ve a huge readers’ base already!

    Review my web site :: find it

  6. proba says:

    Excellent article. I am facing some of these issues as well.
    .

  7. As the admin of this site is working, no question very shortly it will be famous, due to its
    feature contents.

    my website; lower left back pain kidney

  8. For latest news you have to pay a visit internet and on world-wide-web I
    found this web site as a finest web site for most up-to-date
    updates.

  9. good advice says:

    My family every time say that I am wasting my time here at net, however I know I am getting experience
    every day by reading thes nice articles or reviews.

  10. Can you tell us more about this? I’d care to find out some additional information.

    my weblog – king of the jungle baby shower

  11. I’m gone to say to my little brother, that he should also go to see this weblog on regular basis to take updated from most recent information.

  12. Hello there I am so delighted I found your blog, I really found you by
    accident, while I was searching on Askjeeve for something else, Regardless I am here now and would just like to say kudos for a marvelous post and a
    all round exciting blog (I also love the theme/design),
    I don’t have time to browse it all at the moment but I have bookmarked it and also added your RSS feeds, so when I have time I will be back to read
    much more, Please do keep up the great b.

  13. I got this web page from my pal who shared with me regarding this web
    page and now this time I am visiting this site and reading very informative articles at this place.

  14. Fantastic beat ! I wish to apprentice while you amend your web site, how can i
    subscribe for a blog site? The account aided me a applicable deal.
    I were a little bit acquainted of this your broadcast provided bright transparent concept

  15. I always emailed this website post page to all my contacts, as if like to
    read it afterward my contacts will too.

  16. What a stuff of un-ambiguity and preserveness of valuable familiarity
    concerning unexpected feelings.

  17. Wolfgang says:

    I would like to thank you for the efforts you’ve putt in pnning thios blog.
    I’m hoping to vie the same high-grade blog posts by you in thhe future as well.
    In fact, your creative writing abilities has motivated me to get my own blog
    now ;)

  18. Nolan says:

    WOW jսst whaat I was searching fօr. Ϲame Һere Ƅy searching
    fօr custom cat trees vancouver bc

    Feel free tοօ surf tօ my web site friendfeed.ϲom [Nolan]

  19. I am regular reader, how are you everybody? This post posted at this web page is really good.

Leave a Reply