Introduction
There are several ways to add pages into SharePoint page. To day i will illustrate how to add a webpart to SharePoint page through modules using Elements. xml file.
Solution
Step 1: Add a page into Visual Studio SharePoint solution. You can use this post how to do it.
You need a webpart zone to add a webpart, and according to my post the webpart zone ID is WebPartZoneSearch
Step 2: Then create a webpart as your wish.
Then the solution will be looking something like this.
Step 03: Open the Elements.xml file which is inside Module1 and you have to modify it something like this.
- <?xml version="1.0" encoding="utf-8"?>
- <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
- <Module Name="Module1">
- <File Path="Module1\ApplicationPage1.aspx" Url="Module1/ApplicationPage1.aspx" >
- <AllUsersWebPart WebPartOrder ="0" WebPartZoneID ="WebPartZoneSearch">
- <![CDATA[
- <webParts>
- <webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
- <metaData>
- <type name="SitePages.WebPart1.WebPart1, $SharePoint.Project.AssemblyFullName$" />
- <importErrorMessage>Cannot import this Web Part.</importErrorMessage>
- </metaData>
- <data>
- <properties>
- <property name="Title" type="string">WebPart Title</property>
- <property name="Description" type="string">WebPart Title</property>
- </properties>
- </data>
- </webPart>
- </webParts>
- ]]>
- </AllUsersWebPart>
- </File>
- </Module>
- </Elements>
Changes for your code:
Line No 05: You have to add the WebPartZoneID which is from aspx page.
Line No 10: Full Assembly name of your webpart.
Please change both according to your solution.
Conclusion
You can add other property like chrome type through Elements.xml file as well.
Please find the solution here, which may helpful to you.
https://drive.google.com/file/d/0ByEnOE8DAdvheEJaY1RUSkdEM28/view?usp=sharing