Saturday, February 12, 2011

Deploy UserControl to Sharepoint



Here are the steps to deploy.
1. Create a WSPBuilder Project in Visual Studio 2008

2. Add folders to the Project which looks similar to the 12 hive. Put your UserControl (.ascx file) in the ControlTemplates of the 12 hive.


Here, TestUC is the UserControl and is added to the ControlTemplates folder I created. I idea behind this is, once this is deployed, as per the folder structure, the TestUC will be deployed to the ControlTemplates folder in the 12 hive.

Also add the elements.xml and the features.xml to the folder (name of the feature, in this case it is DeployUC)

3. Probably the most important of the steps. Open elements.xml and add the UserControl element to the elements.

3. Create a Code folder and add the TestUC.ascx.cs file. We will link the UserControl to its code file using the Inherits property for the UserControl.


4. Open TestUC.ascx and link the Test.ascx.cs file

If you see, DeployUC.Code is the Namespace under DeployUC assembly under which TestUC (the code-behind file for the UserControl) resides. One this feature is deployed, this assembly sits in GAC and can always be found by the TestUC UserControl.

5. Build and deploy the package and this UserControl is now available for use on to any page.

6. Done.

Post your comments and questions if you have any.

No comments:

Post a Comment