Share via


Creating a Windows SharePoint Services 3.0 Web Part Using Visual Studio 2005 Extensions

Summary: Learn to use the project templates included in Microsoft Visual Studio 2005 extensions for Windows SharePoint Services 3.0 to speed your Web Part development. (5 printed pages)

Alex Malek, Microsoft Corporation

Andrew May, Microsoft Corporation

November 2006

Applies to: Windows SharePoint Services 3.0, Microsoft Visual Studio 2005

Contents

  • Introduction to Web Part Development with Visual Studio 2005 Extensions for Windows SharePoint Services 3.0

  • Creating a New Web Part Solution

  • Customizing the Web Part Solution Package

  • Deploying and Debugging the Web Part

  • Conclusion

  • Additional Resources

Introduction to Web Part Development with Visual Studio 2005 Extensions for Windows SharePoint Services 3.0

Microsoft Visual Studio 2005 extensions for Windows SharePoint Services 3.0 include project templates that enable you to jumpstart your development work for the Windows SharePoint Services environment. In addition, the extensions include a Web Part project template that streamlines the creation, deployment, and testing of Microsoft ASP.NET Web Parts in Windows SharePoint Services.

This article explains how to use the Web Part project template to develop, deploy, and test your ASP.NET Web Parts for Windows SharePoint Services 3.0.

Note

This article assumes you have installed and configured the Visual Studio 2005 extensions for Windows SharePoint Services 3.0. You can download Windows SharePoint Services 3.0 Tools: Visual Studio 2005 Extensions, Version 1.1 from the Microsoft Download Center.

Creating a New Web Part Solution

The Web Part project template included in the extensions is customized especially for creating Web Parts for the Windows SharePoint Services environment.

To create a new Web Part solution

  1. Open Microsoft Visual Studio 2005.

  2. On the File menu, click New, and then select Project.

  3. In Project types, select Visual C#, and then select SharePoint.

    Note

    Currently, the extensions Web Part template supports only Microsoft Visual C#.

  4. In Templates, select Web Part.

  5. Specify a new name, location, or solution name for your Web Part, and then click OK. The extensions create a new Web Part solution project, which includes the following:

    • References to the necessary DLLs

    • AssemblyInfo.cs, a file that enables you to specify company and product information for the Web Part assembly, and version information

    • Temporary.snk, a temporary signature key file for the Web Part assembly

      Note

      This temporary signature key file is only for development purposes. You must generate your own permanent signature key file when your Web Part assembly is ready for production.

    • A Visual C# code file for the Web Part, named the same as the Web Part name

    By default, the code file for the Web Part contains the following:

    • using statements for the necessary System and Windows SharePoint Services namespaces, such as Microsoft.SharePoint, Microsoft.SharePoint.WebControls, and Microsoft.SharePoint.WebPartPages

    • An empty Web Part class that inherits from System.Web.UI.WebControls.WebParts.WebPart

  6. Add the code you want to the Web Part class.

Customizing the Web Part Solution Package

The Web Part project template automatically generates the XML files needed to package your Web Part as a Windows SharePoint Services 3.0 Feature for deployment and activation. The required GUIDs contained in the XML files are also generated automatically.

For more information about Features, see Working with Features.

The extensions generate a .webpart file as the element.xml file for the Feature containing the Web Part. Every Web Part should have a .webpart file, which is an XML file that describes the Web Part. The .webpart file also makes your Web Part appear in the Web Part gallery in Windows SharePoint Services.

You can customize the information in these XML files by editing solution, Feature, and element properties on the SharePoint Solution tab in your project's Properties dialog box, as follows:

  • Solution   Information in this node is written into the manifest.xml file for the Feature. You can set the following solution property:

    • Name   The name of your Web Part solution.
  • Feature   Information in this node is written into the feature.xml file for the Feature. You can set the following feature properties:

    • Folder Name   The name of the folder to contain the files for this Feature.

    • Title   The title of the Feature. Limited to 255 characters.

    • Description   A longer representation of what the Feature does.

    • Version   Specifies a System.Version-compliant representation of the version of a Feature. This can be up to four numbers delimited by decimals that represent a version.

    • Scope   The Feature scope. Can contain one of the following values: Farm (farm), WebApplication (Web application), Site (site collection), or Web (Web site).

      For more information about Feature scope, see Element Scope.

    • Hidden   Hides the feature. This attribute is FALSE by default.

    • Default Resource File   Indicates a common resource file for retrieving Feature XML resources.

      For more information about these attributes, see Feature Element (Feature).

  • Element   Information in this node is written into the element.xml file for the Feature. As mentioned earlier, this file contains the information usually contained in a .webpart file. You can set the following element properties:

    • Title   The title of your Web Part as you want it to appear in the Windows SharePoint Services user interface.

    • Description   The description of your Web Part that you want to appear in the Windows SharePoint Services user interface.

    • ImportErrorMessage   The error string to display if Windows SharePoint Services is unable to import your Web Part solution.

To customize the Web Part solution feature package

  1. In Solution Explorer, right-click the Web Part project, and then select Properties.

  2. In the Properties window, select SharePoint Solution.

    This tab lists the nodes that contain the properties for the solution package that the extensions will generate.

  3. Expand the Solution node, and then expand the Feature node and the Element node.

  4. To edit properties for a node, click a node, and then edit the properties you want.

    For example, click the Element node, and then edit the values for the Title, Description, and ImportErrorMessage keys.

  5. To commit your changes for a node, click in the Description value field.

Deploying and Debugging the Web Part

You can deploy and start debugging your Web Part simply by pressing F5.

Note

For debugging to occur, you must enable ASP debugging on your Windows SharePoint Services installation.

When you press F5, the extensions automatically build, deploy, and initiate debugging of your Web Part solution Feature. To accomplish this, the extensions perform the following actions automatically:

  • Build the Web Part assembly.

  • Package the Web Part solution as a Windows SharePoint Services Feature.

  • If this Web Part solution was deployed previously, the extensions retract the previous version of the Web Part solution Feature.

  • Install your Web Part assembly to the global assembly cache.

  • Deploy and activate your Web Part solution Feature in Windows SharePoint Services.

  • Add your Web Part to the SafeControls list.

  • Restart Microsoft Internet Information Services (IIS) by invoking the iisreset command.

  • Attach to the w3wp processes to enable debugging.

To deploy and debug your Web Part

  1. Press F5. The extensions automatically build, deploy, and initiate debugging of your Web Part solution Feature.

  2. Navigate to the Web Part Page on your SharePoint site where you want to add the Web Part.

  3. In the Web Part page, click Site Actions, and then select Edit Page.

  4. In the Web Part zone where you want to add your Web Part, click Add a Web Part.

  5. In the Add Web Parts dialog box, in the All Web Parts section, under Miscellaneous, select your Web Part and then click OK.

Conclusion

This article described how creating, deploying, and testing Web Part solutions for Windows SharePoint Services is easier than ever before because of the Web Part project templates included in Visual Studio 2005 extensions for Windows SharePoint Services 3.0.

Additional Resources