Share via


Creating Web Parts for SharePoint

Web Parts enable users to directly modify the content, appearance, and behavior of SharePoint site pages by using a browser. Web Parts are server-side controls that run inside a special type of page called a Web Part Page: they are the building blocks of pages that appear on a SharePoint site. For more information about Web Parts in SharePoint, see Building Block: Web Parts.

Visual Studio provides templates that you can use to create Web Parts and debug them on a SharePoint site.

Creating a Web Part in Visual Studio

Create a Web Part by adding a Web Part item to any SharePoint project. You can use a Web Part item in a sandboxed solution or a farm solution.

If you want to design a Web Part visually by using a designer, create a Visual Web Part project or add Visual Web Part item to any SharePoint project. You can use a Visual Web Part item in a farm solution only.

Web Part Item

A Web Part item provides files that enable you to design a Web Part for a SharePoint site. When you add a Web Part item, Visual Studio creates a folder in your project, and then adds several files to the folder. The following table describes each file.

File

Description

Elements.xml

Contains information that is used by the Feature definition file in your project to deploy the Web Part.

.webpart file

Provides information that SharePoint needs to display your Web Part in a Web Part gallery.

Code File

Contains methods that add controls to the Web Part and generate custom content within the Web Part.

For more information, see How to: Create a SharePoint Web Part.

Visual Web Part Item

A Visual Web Part is a Web Part that you create by using the Visual Web Developer designer in Visual Studio. For more information about using this designer, see Visual Web Developer Content Map.

Functionally, a Visual Web Part is no different than a Web Part. A Visual Web Part item includes a Web Part item and a User Control item.

You can design the appearance of the Web Part by dragging controls from the Visual Studio Toolbox to the surface of the user control. For more information, see How to: Create a SharePoint Web Part by Using a Designer.

Debugging a Web Part

You can debug a SharePoint project that contains a Web Part just as you would debug other Visual Studio projects. When you start the Visual Studio debugger, Visual Studio opens the SharePoint site.

To begin debugging your code, add the Web Part to a Web Part page in SharePoint.

For more information about debugging SharePoint projects, see Troubleshooting SharePoint Solutions.

Creating Older Style SharePoint-Based Web Parts

The templates in Visual Studio enable you create custom ASP.NET 2.0 Web Parts for SharePoint. ASP.NET 2.0 Web Parts are built on top of the ASP.NET Web Part infrastructure and are the recommended type for new projects.

In very few cases, you might have to create a Web Part by using the older style SharePoint-based Web Part. You can use Visual Studio to create these types of Web Parts, but Visual Studio does not provide any templates specifically designed to help you create them.

For more information about when it might be appropriate to create an older style SharePoint-based Web Part, see Web Part Infrastructure in Windows SharePoint Services. For more information about how to create a Web Part by using the older style SharePoint-based Web Part, see Walkthrough Creating a Basic SharePoint Web Part.

Title

Description

How to: Create a SharePoint Web Part

Shows you how to create Web Parts for SharePoint pages.

How to: Create a SharePoint Web Part by Using a Designer

Shows you how to create Web Parts for SharePoint by using a visual design surface.

How to: Create a User Control for a SharePoint Application Page or Web Part

Shows you how to create custom, reusable controls that can be consumed by application pages and Web Parts that run in SharePoint.

Walkthrough: Creating a Web Part for SharePoint

Describes how to design a Web Part for SharePoint.

Walkthrough: Creating a Web Part for SharePoint by Using a Designer

Describes how to design a Web Part for SharePoint by dragging controls to a visual design surface.

Working with Visual Web Developer

Describes how to use the designer that appears when you open a Web page in your project.