Followed Steps To Register a Control in SharePoint 2007


Example : Control to deal with Sharepoint List

1 – Create A List in Your Portal  as the following Steps


to customize the List Fields click on Settings >> List Settings,

after that you can add,delete,edit  List Columns

2 – Create new Asp.net Project >> Add New Web User Control to Add New Employee

as the following snapshot :

* Add reference to Microsoft.Sharepoint.dll to your solution

in the Add Button Click write the following Code:

SPWeb mySite = SPContext.Current.Web;

SPListItemCollection listItems = mySite.Lists[“Employees”].Items;

SPListItem item = listItems.Add();

item[“Title”] = TextBox1.Text;

item[“FullName”] = TextBox2.Text;

item[“Email”] = TextBox3.Text;

item[“Mobile”] = TextBox4.Text;

item.Update();


Build Your Project

3 – Make signing for your Assembly


Project Properties >> Signing Tab >> Mark [Sign the assembly] >> choose from the next List  [New]

>> Name it >> Build the Project Again


4 – Open your virtual sharepoint server


4.1 Copy your project’s Dll and paste it in the folloiwng path on the server                C:\WINDOWS\assembly

4.2 Copy your control html only to the following path

C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\CONTROLTEMPLATES

or you can make a folder for your project so the path will be as the folloiwng

C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\CONTROLTEMPLATES\MyProject\Controls\

4.3 open your portal web.config on the server add new assembly key with your project dll to tag <assembly> as the following :

<assemblies>
<add assembly=“MyProject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9a94956654413ddf” />
</assemblies>
you can find assembly name and it’s publickeytoken from the assembly folder by searching for your dll
and right click to get it’s properties
Save the file

5 – Open Sharepoint designer 2007


5.1 open your web portal

5.2 find your list in folder Lists on the left section        don’t forget “Employees” List

5.3 Add new aspx page

to make the page attached to a master page

Format Menu >> Master Page >> Attach Master page

in the page top section

add tag prefix to your control like this

<%@ Register src=”~/_CONTROLTEMPLATES/MyProject/Controls/Add.ascx” tagname=”Addemp”  tagprefix=”UC” %>

in the page body use the control as you see

<UC:Addemp runat=server></UC:Addemp>


6 – Final Step open cmd and reset your iis by the following command

iisreset
 

7 - Test your page and try to add new employee and go to AllItems.aspx page and see the result 

Regards,
asamir@sure.com.sa

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s