- In visual studio 2005, create a new web control library project and code controls as required
- Ensure that the project / assembly is strongly named. (from the menu Project -> <projectname> Properties -> Signing)
- Compile you project into a dll.
- Add the dll to your SharePoint bin directory (this will normally reside at somewhere like C:\Inetpub\wwwroot\wss\VirtualDirectories\41ea6637-fb56-4dcb-8a2e-9d1e91b56a20\bin – check in iismanager to see where the main SharePoint sites home directory is). Note that you could instead add the dll to the GAC if required.
- Add the control to the safe controls node in your main SharePoint web.config (the web.config will normally reside at somewhere like C:\Inetpub\wwwroot\wss\VirtualDirectories\41ea6637-fb56-4dcb-8a2e-9d1e91b56a20). <SafeControl Assembly=”TestSharepointWebControl, Version=184.108.40.206, Culture=neutral, PublicKeyToken=cdfbe353a0e07440″ Namespace=”TestSharepointWebControl” TypeName=”*” Safe=”True” />
- Perform an issreset (not fully sure if this is actually required).
- Add a reference to the control library you have created (ensuring that the version number is correct). E.g. <%@ Register Tagprefix=”TestSharepointWebControl” Namespace=”TestSharepointWebControl” Assembly=”TestSharepointWebControl, Version=220.127.116.11, PublicKeyToken=cdfbe353a0e07440, Culture=neutral” %>
- Call the relevant controls within the masterpage as required. E.g. <TestSharepointWebControl:WebCustomControl1 id=”WebCustomControl1″ runat=”server” />
- Upload the masterpage and checkin / publish accordingly. The master page should now run the relevant controls.
If your webcontrol hooks in to SharePoint, its best to inherit from the SPControl class as opposed to the System.Web.UI.WebControls.WebControl class. If it does hook into the SharePoint object model, add a reference to C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\ISAPI\Microsoft.SharePoint.dll and using statements for Microsoft.SharePoint and Microsoft.SharePoint.WebControls if required.
If you don’t sign, and add to safe controls in web.config (as per the steps described), you will get an error such as The control type “TestSharepointWebControl.WebCustomControl1” is not allowed on this page.