Creating a SharePoint Site Page in Visual Studio

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.

Step One

  • Create an Empty SharePoint Project.

Step Two

  • Add your site and deploy as a farm solution.

  • this is what the solution should look like

Step Three

  • Right click - Add New Item

  • In the dialogue box select choose Module for more information about modules click here

  • Things to note

  • 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

Step Four

  • 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

Step Five

  • 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

Step Six

  • 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

Step Seven

  • Now we can customise the xlm file, for this demo we will add some top of the page navigation.

Step Eight

  • 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.

Step Nine

  • Add the following into the body of the asp:Content area.


  • 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…