Creating Hosted Web Parts

SmartPart is actually a series of web parts created by Jan Teilens (http://weblogs.asp.net/jan). The version for WSS 3.0 is called Return of the SmartPart. To start using it:

  1. Download the SmartPart from http://www.codeplex.com/smartpart.

  2. Follow the instructions provided with the download to install the web part on the server.

  3. Create a UserControls folder in the physical folder for your SharePoint web site. For example:

    C:\Inetpub\wwwroot\wss\VirtualDirectories\2007\UserControls
  4. Deploy your user controls to this UserControls folder.

  5. Add the SmartPart web part to a page, select the user control, and click Apply as shown in Figure 11-1. SmartPart loads the control and displays it on the page.

    Using the SmartPart to host user controls

    Figure 11-1. Using the SmartPart to host user controls

The user control shown in Figure 11-1 uses ASP.NET 2.0 compile-on-the-fly, so I put both the page markup (.acsx) and code (.cs) in the UserControls folder. The HelloSmartPart.ascx sample included with SmartPart packages the code and description in a single file using <script> blocks.

Code that is shared among user controls should be stored in a separate project, compiled, and deployed to the BIN folder in the web site root.

Developing Under Windows XP

One of the tricks in programming web parts is setting up your development environment: the SharePoint DLLs run only under Windows 2003, but most development machines run Windows ...

Get Essential SharePoint 2007, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.