Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

User can create a pages, when a user click on the "create page" link a pop up dialog shows up which is a aspx file, inside this dialog I have created a dropdownlist:

   <div class="ms-formlabel"><asp:Literal ID="LitTitleLabel2" runat="server" Text="Choose pagelayout:"/></div>
   <div class="ms-formbody"></div><asp:DropDownList ID="DropDownList1" runat="server"></asp:DropDownList></div>

I have also created 3 different pagelayouts, How can I create the functionality so that users can choose between three different pagelayouts inside this dropdownlist.

Any kind of help is appreciated!

Note: Users can at the moment type a title for the news in the pop up aspx file and then press "ok" button and then they get redirected to the created page in edit mode.

share|improve this question
add comment

3 Answers

When you select one of those page layouts in your dropdown then you fetch that value by a postback and create a new page in your site based on that page layout.

PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(web);

string pageName = “MyCustomPage.aspx”;

PageLayout currPageLayout = FETCH YOUR PAGE LAYOUT HERE;

PublishingPageCollection pages = publishingWeb.GetPublishingPages();

PublishingPage newPage = pages.Add(pageName,currPageLayout);

newPage.ListItem[FieldId.PublishingPageContent] = “This is my content”;

newPage.ListItem.Update();

newPage.Update();

newPage.CheckIn(“This is just a comment”);

The source for this was fetched from this link: http://www.learningsharepoint.com/2010/09/17/create-publishing-pages-sharepoint-2010-programmatically/

You can fetch all page layouts with PageLayout[] pageLayouts = publishingWeb.GetAvailablePageLayouts(); iterate through them and match that page layout with the one you have selected in your drop down.

Afterwards you redirect to the new page BUT maybe you shouldn't check the page in. Just create it and let the editor check in the page and remember to set the user as editor on the page so you don't get any access issues.

//M

share|improve this answer
    
Where should this code go in? –  Rohander Mar 8 '13 at 8:04
    
You set an event on the drop down and when you do a postback you put this code in. –  Magnus Hansson Mar 8 '13 at 8:24
    
I have a event that sets value in the dropdownlist am I suppose to have this code snippit inside it? and about the PageName variabel what aspx file should be inside of that? –  Rohander Mar 8 '13 at 10:10
    
can you join this chat room please chat.stackexchange.com/rooms/7815/obsi –  Rohander Mar 8 '13 at 10:12
    
You should put it in the OnSelectIndexedChanged Event function. Read more about it here: ezineasp.net/post/… –  Magnus Hansson Mar 9 '13 at 5:15
add comment

There are 2 ways to create pages:

1.Site Actions -> Create Page.

Here by default you can create a "Body Only" layout based page.

2.Site Actions -> More Options

Here you can select the Publishing page option & then select different layouts available.

You are referring the CREATE PAGE under SITE ACTIONS. This option by default creates a page with layout = "Body Only". And the operation happens in the default SharePoint's 14 hive based ASPX file. server:port/_layouts/CreatePublishingPageDialog.aspx?IsDlg=1

You solutions:

  1. Once the page is created, you can use the Ribbon -> Page -> Page Layout drop down.
  2. Change the page layout after the page is created. (Educate users about it)

Below will affect other applications too

  1. Redirect the "Create Page" link to you custom page (change the Site Actions related Menu control in 14 hive) where you fill the drop down with list of page layouts & on CREATE click, create the page using code.
  2. Or change the "CreatePublishingPageDialog.aspx" page in 14 hive, add a user control to it to do the job & hide the existing controls.
share|improve this answer
add comment

Once the page is created you should be able to change the page layout in code using http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.publishing.publishingpage.layout.aspx
All you need is a reference to the page which it sounds like you may already have and a way to reference what layout the use selected (I think you have this already as well). Also make sure to do this before the page is displayed to the user so they get the new layout.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.