First you need to create the custom site page. You could go through and build the page completely within SharePoint Designer (SPD) but, this will at least give us a good starting point for VS.
- Launch Internet Explorer (IE) and navigate to the Site where you wish to create your custom site page. In my case this will be http://localhost/mycustomsite.
- Select Site Actions | Edit in SharePoint Designer.
- Select File | Add Item | New Page from Master | v4.master (Default) | Create. When it asks you, change the name to MyCustomPageTemplate and in my case I am using the Site Pages library. But, you can use any Wiki Page Library you have setup as well.
- Click OK.
- Give it a second or two and when the alert comes up just click Yes.
NOTE: At this point I am assuming C-Sharp (C#) but if you are a Visual Basic (VB) programmer you can just change the language setting in the page tag as is appropriate.
- Switch the page to Design view.
- Locate the PlaceHolderMain(Master) content place holder. It is the open area in the middle of the page for those not familiar. In the menu for it, click Create Custom Content. That menu can be accessed by clicking the little drop-down arrow right on the component itself.
- You can now click into the PlaceHolderMain(Custom) area, notice it says custom now, and it can be editted. Type some placeholder information like "My Content Goes Here".
- Switch the page to Code view.
- Hit [CTRL+A] to highlight all the contents of the page and [CTRL+C] to copy it into your clipboard.
- Save the page and close SPD.
- Launch VS and create a new Empty SharePoint Project. Let's call it the CustomPages project for now.
- Right-click the CustomPages project and select Add | New Item | Module.
- Name the module SitePages or whatever your library is and click Add.
- In the CustomPages project, select File | New File... | Web | Visual Basic or C# | Web Form and click Open.
- Right-click inside the contents of the file (anywhere on the screen should be fine) and select Move Default1.aspx into | CustomPages. Navigate to your SitePages module and save the file there with a name of MyCustomPage.aspx or whatever you want to call it.
NOTE: Make sure that the new page shows up in your Solution Explorer window under the SitePages folder. If it doesn't you may need to drag-and-drop it there.
- Highlight all of the contents of the MyCustomPage.aspx and replace with the contents on your clipboard.
- Expand the Features folder and double-click Feature1 to open its settings.
- Set the feature title to CustomPages (or whatever makes sense) and set an appropriate description.
- Switch back to your solution explorer. Go ahead and delete the Sample.txt document found in your SitePages module folder.
- Open the Elements.xml document for editting. Remove the SitePages/ from the Url. The Path attribute should be left alone.
- Add the attribute Type with the value GhostableInLibrary to the File element you just modified. Also, add a Url of SitePages to the Module element. Should look like something this:<?xml version="1.0" encoding="utf-8"?><Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="SitePages" Url="SitePages">
- Save all of your changes.
In my next blog post I'll describe how to mark your page as safe and show how to enable code-behind for these Site Pages.