Creating a SharePoint Site Page in Visual Studio
This post will show you how to create a SharePoint Site Page within visual studio, we will walk through creating a feature receiver and looking at how to create a page with navigation and some inline code all within in visual studio.
- Right click - Add New Item
- In the dialogue box select choose Module for more information about modules click here
- Modules are how you put things in content databases using a solution package and feature.
- Normally attached to a SPWeb level feature.
- When activated the content gets provisioned in the database portion of the files system
- IMPORTANT - when you de-activate the feature, the content is NOT DELETED automatically - You would need to delete the provisioned things using a feature receiver. For more information on a feature receiver class click here
Things to note
- Now that you have created a module - you will now see the feature within you project solution
- Rename it to the project name or anything you like…
- So your full solution now looks like this below after you installed the module with the default xml file showing
- Within the elements xlm file below you will see that it has automatically created a file path "SiteModule\Sample.txt" and places the file within the content database under "SitePageModule" for that project name
- We are going to rename Sample.txt to Pages.aspx
- Your xml file should now look like this below as Visual studio will automatically change the file name for you but just beware on making lots of customisations as sometimes visual studio just does not keep up so it is always worth a check
- Now we can edit the page and for this demo we will add some inline code.
Delete all of the same text and add the code below so the page will render.
- Now if you deploy or run this in your test environment you will see that the Page is set up in the navigation bar and the current date and time is shown
One thing to note… is that Code blocks are not allowed on Publishing sites and should be managed accordingly depending on your needs the purpose of this demo to show what could\can be done…