I have been developing inside SharePoint for a while now and while things are getting easier with tools I think this process for developing User Controls inside SharePoint gives me a lot of control.
- I have a Graphical User Interface
- I have a separate project to build and test outside of SharePoint
- I can easily update and view my project html and binary code
Currently this process doesn’t create me any SharePoint Solution files to deploy across environments. I think to achieve this I will need to create a VS 2008 SharePoint Project…but so far these projects seem to add weight and time that I don’t want at the moment…while I am developing.
- Create a VS2008 web project
- In IIS create an IIS Application under your SharePoint web site that has a path to your VS2008 web project created above. This helps for updating content
- In your VS2008 project create some user controls and test that they function
- In VS2008 project properties under the Build Events tab point the Post Build events text box and add a copy statement to copy your .dlls and .pdbs to your SharePoint web sites bin directory. This will deploy a new .dll every time you build your VS2008 project. I had problems when I put the VS2008 project .dll into the GAC…it only worked when I put it into the SharePoint’s web sites bin directory
- Update your master page with CSS references if your VS2008 project contains a style sheet.
- In SPD in your Page Layout add a Register directive to register your user control
“<%@ Register Src=”~/UI/UserControls/JobGoals.ascx” TagPrefix=”uc1″ TagName=”JobGoals” %>”
OR
Update the SharePoint web site web.config file
<pages>
<controls>
<add src=”~/UI/UserControls/MyAttributes.ascx” tagPrefix=”uc1″ tagName=”MyAttributes”/>
<add src=”~/UI/UserControls/JobGoals.ascx” tagPrefix=”uc1″ tagName=”JobGoals” />
</controls>
</pages>
- Add the User Control to the Page Layout
<uc1:JobGoals ID=”JobGoals1″ runat=”server” />
- Update the SharePoinnt web sites web.config file
<SafeControl Src=”~/UI/*” IncludeSubFolders=”True” Safe=”True” AllowRemoteDesigner=”True” />
- Restart IIS, navigate to a page that uses the page layout and you should see your User Control
Because we created a IIS Application under our SharePoint web site and mapped our VS2008 projects .dll output path to our SharePoints web site, updates are extremely simple.
- .ascx changes: modify, save in VS2008 and refresh sharepoint browser
- .ascx.cs changes: modify, save, build in VS2008 and refresh sharepoint browser