Sunday, 21 December 2014

How to create page layout in SharePoint 2010 using visual studio 2010


We know that we can create page layout using SharePoint Designer but how to create page layout using visual studio 2010.


here am trying to show how to create page layout using visual studio in SharePoint 2010.


Here am taking article page as parent page. For this need to activate two features


a) SharePoint Server Publishing Infrastructure.(This feature available in  Site collection features which is under site collection administration)
b) SharePoint Server Publishing.(This feature is available in Manage site features which is under Site Actions)


if these two features are not activated then we wont see article page content type in Content Types. see the image.


https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvyG85c1hl5lL86iKLH8LjTQX0xve3MqZwGfj0XMoy8jHivWm9iMOB4xPF_rDdI2B-mY_onKderlV7QUWz152hH11butKFm8NIl4iAwtGHXfxGJgLchvvcH8n9e9OfyyqrRK12bzv1sK5E/s1600/stepAllContentTypeBeforepublic.png


 activate these two features



 https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9gMm_bsNsBO9NlV-rEzydH499cPaBSAP3NVzc7m7Fe7hf7mx3nenqFYqG6rC7_Axw_7HUWpEWO5zdeHOlL8NnXsdxVDKQ6uhDXe_I_n6xmptf45w4_pZQ6EUJ3vYSjZg4-VR7tIMDKmF-/s1600/ActivateFeatures.png

 1) Open visual studio --> File--> New --> Project.


2) Select SharePoint 2010 in left panel, then select Content Type template in the middle panel and then specify project name.



 https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi92tDSp_VcojzzDO8DIrYOh4moX9xnwGFJTzQcsJnR_n2ASQF1QUgcEowB-NzRqSv1jQMKHoRyO4Xb2IhjCiZFtIpIck6NzlImHxMid0ZDA2AuVJaS7mFGN146K1QeyqaArDy-QoU1bHBf/s1600/step2.png


 3) Specify URL location for debugging and deploying this solution as sandbox solution for testing purpose only.

 https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwHUQRaYn9XjZytbKQv7Io4hs7_mAqu1D46n8foA-y-iE3RL7eHd980yIpQfd0KXE0StYhyphenhyphenFPN7PHBlPmkuHR6qO-vQurrdwYBxyMjkA0JVj0Ta9M4ciMeFna4JbIWphdvZeOk1-sJY63s/s1600/step3.png


 4) Choose Content Type from the drop down here am selecting 'Article Page' and Click on Next.

 https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAZpD8RFXmO2HwRO-cpSxLzN04A00N2rIJRL86YXHoB4v7b68W8qPDyIiMDnWBXcy_RCuo3lTOSuAfo0NNVY8fFC7SgrsKh2UxGt36ExGHSaxI4lCPoJL_qOebRytDC-Q8hb2iEfObuXwt/s1600/step4.png

 5) Now it will automatically open Elements.xml file of ContentType1. Now modifying Name of the Content Type and save the file.


https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjyJyhW1hXPwksWVLEjSKE2Df4HYo1bHWVECuWkZfLXjPZC_jvQ_UHuQLuNEU6UhlfuFc_UlSTwYJ6IwRIJzuDMde1pcFzvOIPovk8XhY8yD_-0mmU5aNi5QBF_-tVzdAALaT-ffnrJnpUA/s1600/step5.png 

 6) Now Add Module for actual pagelayout name it as PageLayoutModule

 https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtmfP-z6wftsBXO6P1rVNuVqp4PINqJjtkDkaqBuwF_jcHntHY9pFnqGLgAV-zfgPkRAoIBey7NBKhPIVeK5SD8mwToi2TiNmCgRt4kcDyU82tJRY3gfBXMrCkKIC-DCSk6LPplrUNDbuk/s1600/step6.png


https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjy5x6RjTb4cvIn1_kw03aNzUiS8AybbaP6lWf_WbUCKS-u9H1R0PsbgFxsO2n5mT8JEJu1E93N_zdfnGhhzPzGCIzn5ecjkyUnXwRQKMbr7gOEvOTc7KYstzpcPX2VRcwX6-5ALN0a7YrG/s1600/step7.png


By default module has two files one is Elements.xml and sample.txt


7) Now delete sample.txt file from PageLayoutModule



https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7GzODnnbtS6MRuPPE1rKx0kCE1ZGyZQY0EAdRNPKqf2O5mSbrEztyOJs4aPFt0zXVay5s2FDcD7_f43Sl6Z4sRu_Dw2jL_BQvA9O5f-6zDE2VyxKBXiMRSgJ8WSOxFrN5PS831B7QYMba/s1600/step8.png



8) Now adding pagelayout page i.e UdayPageLayout.aspx to PageLayoutModule.

https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiwxOQpoOUG-3AW63upqdcgwhDbOrKHm862W3l4MmQ9B67BBVWX42b5VCB9x7Yk3XoCSxfNOY_LNQx-7WxgxCcuUmwn2umjXxdfLmcZCJFfv8WOxtIaBYvrvC8Xq6Eegz7HcZS8iktuTaew/s1600/step9.png

 9) Design pagelayout. Here am adding one table in that am adding three webpart zones.


These webpart zones are used to place webpart.


 https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3CRXbo-vjjOdSHO3yJnOBGUFRbPD6YsVGCfKYr1vfTR3qQ22Ie18V6kSMHM-ffxerzh9VUjIOgSi1EQXNGSCLaZEVxRTQuZYlRmdRwYFvG_NvHtVc1o0l__i8HOLKHwwdV2ncx9yqAiXI/s1600/step10.png


 here the code which i was used.



<%@ Page Language="C#" Inherits="Microsoft.SharePoint.Publishing.PublishingLayoutPage,Microsoft.SharePoint.Publishing,Version=14.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" %>


<%@ Register TagPrefix="SharePointWebControls" Namespace="Microsoft.SharePoint.WebControls"
    Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages"
    Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="PublishingWebControls" Namespace="Microsoft.SharePoint.Publishing.WebControls"
    Assembly="Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="PublishingNavigation" Namespace="Microsoft.SharePoint.Publishing.Navigation"
    Assembly="Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<asp:content contentplaceholderid="PlaceHolderPageTitle" runat="server">
<SharePointWebControls:FieldValue id="PageTitle" FieldName="Title" runat="server" />
</asp:content>
<asp:content contentplaceholderid="PlaceHolderMain" runat="server">
<table cellspacing="0" border="0" width="100%" cellpadding="0>
  <tr>
       <td width="100%">
       <WebPartPages:WebPartZone runat="server" FrameType="TitleBarOnly" ID="Top" Title="loc:Top" />
       </td>
       </tr>
       <tr>
       <td>
       <table width="100%">
       <tr>
       <td width="50%">
       <WebPartPages:WebPartZone runat="server" FrameType="TitleBarOnly" ID="Left" Title="loc:left" />
       </td>
       <td width="50%">
       <WebPartPages:WebPartZone runat="server" FrameType="TitleBarOnly" ID="Right" Title="loc:right" />
       </td>
       </tr>
       </table>
       </td>
       </tr>
       </table>
</asp:content>





10) Now open Elements.xml which is under PageLayoutModule and it looks like this.



 https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjpoXBGgL1OdKw4ohBCUlYow2_g1NR7hGHjUOFU-8tiBAyLlXfQDdcDZi16aItCr7P0Z3bT3KdnnZO2QzKmM0frT7FEZq-xX7-oAhl0T9-nAzWMk0wiXW91yQds2QOOs3Kc2WBHEXb_NfF/s1600/step11.png


 11) Now change File tag's URL attribute because inorder to display your custom pagelayout in pagelayouts(which is in ribbon while the page in edit mode).


 https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQOoe3G_Ofs39i_983CLWqCm1EBMmfSLXkhuaYQQowOkEuI7jcQKrejsOPt-V9PJXaWpAWgtn_B62SYSR06Vlq9xX5zdiPZJSK6YuRJ6d01YgD3UBhka60U4Yquf3fZbwRGSGM58UtG_tp/s1600/step12.png


 12) Now am adding properties to page layout. in this we specify Title of the page layout and ContentType i.e pagelayout content type and PublishingAssociatedContentType i.e name of the parent content type and Content Type ID of the Elements.xml which is under ContentType1.


https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjMmP0_nTcBrGb-GALCSIU6TtWX_zv03IGsdjAeLHksCptTra5Sp38JysK-a0dQIisG0CLrfmhWCwREZ9EhA6oKFHKHLV9xaNUGys6S2gyZxbwMkdEpv28ugIhr0fJfYFdHu6xDr9WH4s05/s1600/namedisplay.png


And also Add URL attribute in Module tag.



https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgD_2t9IOfaifGqpM_RNbM5wcUGOhce8VYTpHd4PefEA7G1AIK92dfeu57tJEvkKd4_7ERJfmufAT_sTYD3AiQYx2pLb2JVdEiMqkthgLANBuG_0JY3ZMV1wrGVIdF-G5fPzgSmTVVh7Dr6/s1600/step13.png


https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieZa2Jx1LBfhyiV2sska5VK41wkwt4gxjJJkVW-zvJc1Wc69ow5DfWek12HbovgN7D9oBWKrGxG8DrBcVBRQEO7xvZr2ue2C5AAOpYObeZyyk73Z4d2S0s_tl6PPxfPhLbvVzTLGQ0QneE/s1600/contentTypeid.png


13) Now open Features-->Feature1, ContentType1 and PageLayoutModule are in Items in the Solution.

https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYuC_c2SStzYi1SDIgOU6tI5qihS5Or4XDRnXh3zCAHTVW2wszRLfwe3XxX-25iE4uDFc4j2Vzvp8IQPL-VLwZC0e77pnmlfz_MD4n4C_kWFHVvUc_6iNWy-Wd4n8lmPwZCtaZyYt1j_ce/s1600/step14.png


Move these two items to Items in the Feature.

https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjEukqIpdYyNmbEaOejQ-ZJU25vSl9czckVoPVe17SNFxFE89zuX_pesmfgD3gWh_JTLHuQQMExOrRvXZ3iUNxWLwm9BbjkhlCivIVSXt1bxlLuqXK-GkuFn7HE_4wsH4mUQlXQTlb__iq3/s1600/step15.png


15) Now deployee the solution.


After successfully solution deploye. The page layout is available at http://<<server>>:<<port>>/_Catalogs/masterpage (_Catalogs/masterpage) is specified in pagelayoutmodule.
To go that page follow these steps


16) Now open your site --> site actions -->site settings, Click on Master pages and layouts which is uder Galleries.


https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjit-YefQIkRKtQmYF938C2xvwk_DZtdn9e8KXQ0jvfcb3KdfStfIULa_-6zUeYKFF1BXupIzA6TnDARO3AHJmGpKcev3mBbWIqF27ra3-oS40OdjGF2YgCm3e6az_aoiM-kq17rRpDNwmu/s1600/step17.png


17) Now you can find newly deployed pagelayout file in the list of files and its status as "Draft".


https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhVPEnXtu_pK16vN6cujx4SlT5tk8ovrCaz54z3dbese_yih73dkElZ8PKqlJ38kU4H5YKDNWJlP4xK6Kv2IdDwz8tQL03w8cUjA8AEBFx-d8DpJon1MFSCj0Qo5sdLj9SoragdMw3calV2/s1600/step18.png


18) Now checkin the newly added pagelayout file. we can do it in two ways. one is through ribbon and through item menu.


https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiIBKZZ-sHIdm6TtwaZ6g38HbV45PBU4JOtdCR9zryjgpJClIvpRRlnFWppHvSNM_su1BuJwJJlUQh3Zus_SHFRPvHDN5JOKkfyaPNIpk_yoPGOM9v2Z3GIZyZ1KJojlC9xRNqEKjkGCxJH/s1600/step19.png


19) While checkin select major version and add your comments and click on "OK".


https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiM88nWNi7cWwn2LCyzfWLft1_G8uJNeUo8YKqCdHeSaZ-HMypN2TxWB1WLXBFPi7JtjNksnE9l6IFshGOY0fPIcnfftoGsFkhnS5vdo8_N8HCqgPELwNtrBNIwo8ISDgm_3CfbW6pHUpHL/s1600/step20.png


20) Now the pagelayout status changes to pending it means we need to approve it.


Select the pagelayout and click on "Approve/Reject" from ribbon.



https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjI2f8G8yWcV2ulPy3Lu5NeKkFMCaIcxPUCIu4Ns4MkMvd0gYT-Od_IPFDLUe29vQffF2GHo6aUB1WLTcDj7PsnLvyRucPG_mFnQul8fdTF3Q1b6YyWgR8tmjnPg9aFJiUorQllpv2MEWPm/s1600/step21.png


21) Then select "Approved" radio button in Approval Status. Click on "OK".


https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibzS9woCDUA908A9EpUtZ0mN0KAZnDrHzYoEUlKRJ1HA972VjQkt6A7R3tOKCsk_j_OF0ZjlXX3P3fx-K7NHY8Vp1kI-BtmmujGkaK4OAqUgEFvLTAM_TOt0ihL299AeFpMPIwUa55A6cN/s1600/step22.png





22) Now the pagelayout file status is approved, so that pagelayout is available.



https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgsid8RRm1ZQIEbJs-CuYpfk4hzZmrMSW9_xCa-tKtxXmvEJ-kd0khpUtwO7eGGzxo22lg3yU7B5OZvdVk8mu8RoQQr0SNl5RrALpiB45I9yJoTRy2lMY3mBFUBrEP2NzjBVZk66OSXmfUO/s1600/step23.png


23) Now Go to Site Actions --> More Options.


https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8UmUF8zlP3F6AMh7Im1yPwppaSzQWEH_qu7DSHOoTtjLJ20cz2hSPdGNVSGPKUTDbYA58e07B9IFYY9Ni8LnjAnslCii5OWh3bDJ9Sg5lFzfdI5kuptzPzclAW9FH_qCU-kTn9vqbgiuT/s1600/step24.png


24) Select Page in left panel and click on Publishing page.Now click on Create.

https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJSGAF5cKmAt4l_eMDfO3sRaIzO8DgkDubp_anL7frQ8RQk2h6O-l6j-EkAFYXpfc7j1334_gZlUX9NUOaK-rUrz0GUjkcIfa5L-xvLQdBjWWqNaopxfpqNjd1rt7JIOVfBDsu9lM3LT-_/s1600/step25.png


25) Now you can see newly added pagelayout as (Name of the content type which is in Elements.xml file under layout1) Title value in Elements.xml which is under PageLayoutModule.i.e (CustomePagelayoutSample) Custome Page Layout.


https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhcSaHxb3A9uq_7p10TnHa2Q_3Mh65bCo76vGAM_MyrzrD85u8CdQI0ZXCO86t7yJKQ4mlXGrdTwm-rm_Z36Bakx7v0WoOeurmghR5vaq-D2Tm_XxB2Qqhdq_F8XW90wymv_6D2COTe360M/s1600/step26.png



https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjMmP0_nTcBrGb-GALCSIU6TtWX_zv03IGsdjAeLHksCptTra5Sp38JysK-a0dQIisG0CLrfmhWCwREZ9EhA6oKFHKHLV9xaNUGys6S2gyZxbwMkdEpv28ugIhr0fJfYFdHu6xDr9WH4s05/s1600/namedisplay.png




now click on Create.



https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhaoV4qyXnRfdg7d-yieGRRQWudTwa4rXl2BwAMzWcufCbZQ_j1Wgt_4MedMlDt9op0AHjzNzKFwGJf3GvMYLKIZgRmoOxOiMlCl97Ts36BeK0dAfUxCIRlEy1pouX2-NBLrGBwA1NtkIb8/s1600/step27.png


26) Now you can aslo see the newly added content page layout in page layouts(which is in ribbon).


https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj00rBp_w_DgQ6prp_EEFseTNRsCNQovKRbUSRqy9gWmu7n-Pl0x4JEOLVYIHe3fI791MhJ2L3itPorwm7MUBUno3VkhmpLdGtsSrHM6jLj1L7hWdh-K-IWvxydm1ztUYDLNDQwOsXVUm0n/s1600/step28.png


Now you can add your webparts in webpart zones. And CheckIn Then Publish the page.






Reference:

http://www.c-sharpcorner.com/Forums/Thread/182458/how-to-create-page-layout-in-sharepoint-2010-using-visual-st.aspx

No comments:

Post a Comment