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: 2% [?]
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
Cool, just what I was looking for, thanks !
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
Excellent article. I am facing some of these issues as well.
.
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
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.
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.
Can you tell us more about this? I’d care to find out some additional information.
my weblog – king of the jungle baby shower
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.
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.
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.
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
I always emailed this website post page to all my contacts, as if like to
read it afterward my contacts will too.
What a stuff of un-ambiguity and preserveness of valuable familiarity
concerning unexpected feelings.
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
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]
I am regular reader, how are you everybody? This post posted at this web page is really good.
An outstanding share! I’ve just forwarded this onto a colleague who was conducting
a little research on this. And he in fact ordered me breakfast because
I stumbled upon it for him… lol. So let me reword this….
Thanks for the meal!! But yeah, thanx for spending some time to discuss this topic here
on your internet site.
Hi, I desire to subscribe for this web site to get most recent
updates, thus where can i do it please help.