Navigation Bar

Thursday 9 May 2013

Provisioning WebParts through Module

If you want to provision a web-part (or many) for a Page(s) through Module, here is what I use in my project (especially WCM)

I alway create a Feature (as I love it) and it gives Administrator a control to add or remove functionality and also it gives flexibility for deployment. I will share my WCM project structure in future. So stay tuned to my site please.

Before creating Visual Studio Project, please follow below steps:

1. Create a page using your desired page layout (or the page you want to package)

2. Download a copy of the page you created in step 1.
3. Insert Content Editor or the webpart you want to include in the page using Module. For simplicity I am using Content Editor web-part.
4. Configure above added web-part. For instance add image or add some javascript whatever you want to do.
5. Export web-part and save the file.

Now create a Visual Studio Project for SharePoint and follow below steps:
1. Create Module or SharePoint mapped folder to drop required files
2. Create a Module, name it for instance HomePageModule and copy the file (from step 2 in before section) and configure Pages library of desired site.
3. Copy the contents from exported web-part file. Do NOT copy <webparts> node
4. Check whether the contents has got <!CDATA section, if yes then Encode the ONLY text srrounded by <!CDATA[[ and ]]> section and replace <!CDATA[[<your encoded html>]]> with encoded html
5. Add <AllUserWebPart WebPartZoneID="Zone 1" ZoneOrder="1"><!CDATA[[your copied text goes here]]>
6. Add Feature and include above created Module.
7. Deploy the Feature and you will see the page with configured web-part


Happy coding !!!

No comments:

Post a Comment