Pages

Friday, November 13, 2009

Add Custom aspx Pages to SharePoint using _layouts approach

This method is the simplest of all. Here web application pages are deployed under the '_layouts' folder of SharePoint and the pages can be accessed from any SharePoint site. 'Layouts' is a special directory that gets ‘virtualized’ in each SharePoint site. I.e. In each SharePoint will have a /_layouts path from the root of the web.

Here we go with the step by step process in implementing....

Step1: Create a New Project with SharePoint’s Empty template:
In visual Studio 2008, create a new project with Empty project template. Name it as ‘Applciation1’ as shown in Fig1 and give ok.
This is one of the visual studio extensions for windows SharePoint Services template.

Fig1. Create New Project


Step2: Create a New Template Item to the Project:
Now right click the ‘Application1’project and give add new item as shown in Fig2

Fig2. Add New Item

Now from in add new Item dialog box, select on Template under share point as shown in Fig3. And name it as ‘TestPage.aspx’. This adds a new template folder containing TestPage.aspx to the application.

Fig3. Add New Template


Step3: Format the Path of New aspx Page:

Add a new folder “LAYOUTS” under Template, and add any folders into it as required. Finally place the aspx pages into this folder. Now the solution explorer resembles as shown in Fig4.


Fig4. Solution Explorer



Step4: Build and Deploy the Solution:
Now right click the solution and give build and deploy. This creates a new folder Malathy in SharePoint’s Template/LAYOUTS folder. In my case the path is “c:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\MALATHY”. And the aspx pages are stored in Malathy folder.

Step5: View in SharePoint:
Browse the Page
http://ServerName:PortNumber/_layouts/Malathy/TestPage.aspx

Sample output:


Fig5. Sample Output

Pros:

Very Simple way to make the functionality available in every site.

Easy to develop.


Cons:

Cant use the ASP.Net master page of the site context as the _layouts applications is a separate ASP.Net application.


Conclusion:

It is best to use this approach based application when you want to extend every site with some functionality such as additional administration pages.


No comments:

Post a Comment