Compartir a través de


Getting Started with Programmatically Customizing a SharePoint Web Site in Visual Studio

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

The Microsoft Visual Studio 2005 integrated development environment (IDE) offers the premier environment for customizing Web sites based on Windows SharePoint Services. You can create, for example, Windows applications, console applications, or class libraries, as well as browser-based Web applications (called an "ASP.NET Web site" or "Web application" in Visual Studio) and Web services that implement the Windows SharePoint Services object model. You run code that uses namespaces of the Microsoft.SharePoint assembly on the server that runs the deployment, while applications that use SharePoint Web services run remotely from a client computer. To develop Web applications and Web services, you can run Visual Studio either on the same server that runs Windows SharePoint Services or on a remote computer, as described in the following procedures.

Note

To customize Windows SharePoint Services 3.0 through its object model or Web services, you must use Visual Studio 2005, not an earlier version.

After you determine the type of application to create for your task, you must specify an appropriate location at which to create the project. After the project is created, you must set a reference to Microsoft.SharePoint.dll.

To create a project, ASP.NET Web site, or file

  1. Open Visual Studio, and on the File menu, point to New. You will see a drop-down list with Project, Web Site, and File as possible selections.

  2. Choose the type of application you want to create:

    • To create a Windows application, console application, or class library, click Project.

    • To create an ASP.NET Web application (Web Site) or Web service, click Web Site.

    • To create an individual file, such as a Web Form, User Control, or Master Page, click File.

  3. Depending on your selection in Step 2, perform one of the following procedures in the dialog box that opens.

    To create a Project in the New Project dialog box

    1. In the Project types box, select the language and type of project.

    2. In the Templates box, select the appropriate Visual Studio template.

    3. Specify a name and location for the project, and click OK.

    To create a Web Site in the New Web Site dialog box

    1. In the Templates box, choose the appropriate template.

    2. In the Location and Language boxes, select HTTP and the language of your choice.

    3. If you are creating a Web application, type a path in one of the following formats:

      http://MyServer/_layouts/MyApplicationName
      http://MyAdminServer:Port#/MyApplicationName
      

      The first format creates the application in \\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS, and the second format creates the application in \\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\ADMIN. Create applications in the administrative directory that use the Microsoft.SharePoint.Administration namespace to work with global settings.

      If you are creating a custom Web service on the server that implements the Windows SharePoint Services object model, specify a path in the following form:

      http://IISWebSiteName:Port#/MyApplicationName

      For more information about creating a custom Web service that uses the Windows SharePoint Services object model, see Walkthrough: Creating a Custom Web Service.

    4. Click OK to create the application. If you receive a message indicating that debugging is not enabled, make sure Add a new web.config file with debugging enabled is selected, and then click OK.

    To create a file in the New File dialog box

    1. In the Categories box, select the language of your choice.

    2. In the Templates box, select the appropriate template and click OK.

    3. If you are creating a User Control, copy the .ascx file to Local_Drive:\\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\CONTROLTEMPLATES. If you are creating an ASPX page, copy the .aspx file either to \\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS, or to \\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\ADMIN if your code uses the Microsoft.SharePoint.Administration namespace to modify global settings.

Creating a Web Site or Project Remotely

If you are writing code in a Visual Studio installation on a remote computer, create a Project or Web Site within the file system of the server running Windows SharePoint Services. Open the same dialog boxes as indicated previously, but specify a path in this format: \\Computer_Name\Drive$\.... If you are creating a Web application, for example, specify File System in the Location box and use a path such as the following to create the application within the /_layouts virtual directory: \\Computer_Name\Drive$\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\MyApplication.

Setting a Reference to the Microsoft.SharePoint Assembly

After creating a project, add a reference to the Microsoft.SharePoint assembly to import its namespaces and implement IntelliSense features in the Object Browser and Code Editor.

To add a reference to the Microsoft.SharePoint assembly

  1. In Solution Explorer, right-click the project, and then click Add Reference on the shortcut menu.

  2. On the .NET tab of the Add Reference dialog box, select Windows SharePoint Services in the list of components, and then click OK.

    To run or debug code that uses the Microsoft.SharePoint assembly, you must run the code on the server running Windows SharePoint Services. If you are using Visual Studio 2005 on a remote computer, you cannot run or debug code that uses the object model. However, you can set a remote reference to the assembly to write code and see the Microsoft.SharePoint assembly represented in the Code Editor. To add a remote reference in this way, do the following:

    • Click the Browse tab of the Add Reference dialog box and navigate to Microsoft.SharePoint.dll in the \\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\ISAPI folder on the server running Windows SharePoint Services. You may instead want to copy Microsoft.SharePoint.dll from this folder to a local drive on the remote computer, and then open this local copy of the DLL. Click Open.

IntelliSense

Within the IDE of Visual Studio 2005, IntelliSense features are provided for namespaces in the Microsoft.SharePoint assembly after a reference is set to this assembly. The file that provides the information used by IntelliSense for Windows SharePoint Services is Microsoft.SharePoint.xml, which is installed in the path Local_Drive:\\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\ISAPI on each front-end Web server in the deployment. For updates to this file, visit the Windows SharePoint Services Developer Center.

See Also

Reference

Determining Where to Build a Custom Application

Concepts

Getting References to Sites, Web Applications, and other Key Objects

How Do I... in Windows SharePoint Services

Working with List Objects and Collections

Other Resources

Sample Object Model Tasks