Open Visual Studio 2005 and begin a class project. It may seem
odd that you are beginning with a class project, rather than an ASPX project,
but more will soon be revealed.
Right mouse on references and select Add. You have likely noticed
this before, but don't be surprised or concerned when it takes time for the
desired window to pop up in place.
Select the "browse" tab and enter “C:\Program
Files\Common Files\Microsoft Shared\Web Server Extensions\12\ISAPI\Microsoft.SharePoint.dll”
if you're using a standard install.
Do the same for "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Web.dll"
NOTE: It should
make sense that you would add a reference to the SharePoint assembly but the
manual reference to the assembly "System.Web.dll", might be a bit of
a surprise. This goes back to the information described above… you are starting
with a windows assembly project, but you need to add the information required
to manually build ASPX pages. You will see more information like this as move
Rename the namespace, class, and file as desired.
Compile to ensure all is in order (<Control> +
In the root of the project add a folder named TEMPLATE.
Inside that, add directories named FEATURES, IMAGES and LAYOUTS.
Note that this example will not use UserControls on the page(s),
but if you were to do so you would add a CONTROLTEMPLATES directory as well,
which would hold the user controls. Recall the intent (as described in the
previous articles, Developing and Deploying a SharePoint Feature - Part 1 and
Developing and Deploying a SharePoint Feature - Part 2, found by way of the
is to duplicate the directory structure found at "C:\Program Files\Common
Files\Microsoft Shared\web server extensions\12\TEMPLATE". In description
of the directories we have created, the FEATURES directory is where we will
turn on and off this functionality. The IMAGES directory is pretty straight
forward, and while the LAYOUTS directory may not be as obvious by the name.
This is where your ASPX pages will be placed.
At this point it is it is important to acknowledge the intended
name of the project because various sub-directories use this name. We will use
DevAppPages, and as such each of the directories used will get a sub-directory
Next we will create an ASPX page inside the LAYOUTS\ DevAppPages
directory. Since we did not start this application as a web application we will
not have the selection of a web page to add to our project, necessitating that
we do this from scratch. Luckily there is not very much that needs to be added
to a text file to make it an ASPX page.
Start by naming it what you want with an .ASPX extension.
Add an ASPX type reference to the four part version of the
SharePoint DLL. In this case it is "<%@ Assembly
Name="Microsoft.SharePoint, Version=184.108.40.206, Culture=neutral, PublicKeyToken=71e9bce111e9429c"%>"
Add the four part name of the assembly for this project.
Using the project properties, assign a public key.
open the compiled assembly in Reflector and copy everything from Name to the
end of the public key token, being sure to change various characters as needed,
such as the ":" after the name for "=" and adding double
quotes where needed.
The end result should be "<%@ Assembly Name="Pages,
Version=220.127.116.11, Culture=neutral, PublicKeyToken=c475c2fd38120dac" %>",
or your version of it.
Finally add the Page declaration and the appropriate entries,
"<%@ Page Language="C#"
Notice the location of the MasterPageFile… clearly this is
intended for when the page reaches its final location.
Before I continue, I want to give credit to Ameet Phadnis for
publishing an excellent article at http://aspalliance.com/1376_Customizing_WSS_30_with_Master_Pages,
which covers (as it says) Customizing WSS 3.0 pages. He also references the
Microsoft page http://office.microsoft.com/en-us/sharepointdesigner/HA101651201033.aspx#1,
which, among other points, has a list of Content Placeholder names and
descriptions that you will find helpful.
Now drop to the bottom of the page and manually add a place
holder, "<asp:Content ID="Main"
Do the same for "<asp:Content ID="PageTitle"
Save and switch to the Design view and make various adjustments
as desired, including adding a label that will be filled out later with the
Switch to the AppPage1.cs file and (if you have not already) add
the using statements for a web page and of course a reference to the SharePoint
assembly. Also add a reference to the SharePoint.WebControls assembly. As you
are likely aware, SharePoint sits on ASP.NET and inherits much of its
functionality from it. This is the way to reference SharePoint's inherited
functionality for building web controls.
In the name of the class, add the inheritance to the
LayoutsBasePage. While on this step, ensure that the class is set as public.
In order for this class and the ASPX page to work together
properly, since they were not added at the same time you need to add the
required control references on the page to the class where you need
interactivity. As such, since you will not affect the functionality of the
placeholders, you do not need to reference them, but since you want to use the
label in the page from the class, you want to make a reference to a label. The
.NET and ASP.NET runtime will make the leap to link the two so long as the
names match up. If you think about it, this is what an automated ASP.NET
project is doing via Visual Studio. You are simply doing it manually here.
Now make use of the page OnLoad event. You can place the next
statement inside this block or outside.
Use the following statements on two different lines to
"drill into" the site to get the name, then add it to the label…
"SPSite siteCollection = this.Site;", "SPWeb site = this.Web;",
"LabelSiteName.Text = site.Title;".
That is it… you are complete with this stage. At this point your
page and its corresponding class / assembly are complete.