Deploying a Project Task List Definition

來源:互聯網
上載者:User
Walkthrough: Deploying a Project Task List Definition         

This walkthrough shows you how to use Visual Studio 2010 to create, customize, debug, and deploy a SharePoint list definition to track project tasks.

This walkthrough illustrates the following tasks:

  • Creating a SharePoint list definition project that contains tasks.

  • Adding the list definition to a SharePoint feature.

  • Adding an event receiver to the list.

  • Creating and customizing a SharePoint package to deploy your feature.

  • Building and deploying your SharePoint solution.

Note

Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information,
see Visual Studio Settings.

Prerequisites

You need the following components to complete this walkthrough:

  • Supported editions of Microsoft Windows and SharePoint.For more information, see
    Requirements for Developing SharePoint Solutions.

  • Visual Studio 2010 Professional or an edition of Visual Studio Application Lifecycle Management (ALM).

Creating a SharePoint List Definition

Create a SharePoint list definition project and associate the list definition with tasks.

To create a SharePoint list definition project
  1. Open the New Project dialog box, expand the
    SharePoint node, and then click 2010.

  2. In the Templates pane, select
    ListDefinition, name the project ProjectTaskList, and then click
    OK.

    The SharePoint Customization Wizard
    appears.

  3. Type the local SharePoint site that you use for debugging, and then click
    Next.

  4. For the Display Name of the list, type
    Project Task List.

  5. In the What is the type of the list definition drop-down menu, select
    Tasks, and then click Finish.

    The list definition, list instance, feature, and package appear in
    Solution Explorer.

Adding an Event Receiver

In the task list definition, you can add an event receiver that automatically sets the due date and description of the task.The following procedure adds a simple event handler to the
list instance as an event receiver.

To add an event receiver
  1. Right-click the project node, point to
    Add, and then click New Item.

  2. In the list of SharePoint 2010 templates, select
    Event Receiver and name it ProjectTaskListEventReceiver.

    The SharePoint Customization Wizard appears.

  3. On the Choose Event Receiver Settings page, select
    List Item Events as the event receiver type.

  4. Set the Event source item to
    ProjectTaskList.

  5. In the list of events to handle, check the box next to
    An item was added and then click Finish.

    A new event receiver node is added to the project with a code file that is named
    ProjectTaskListEventReceiver.

  6. Add code to the ItemAdded method in the
    ProjectTaskListEventReceiver code file.Each time a new task is added, a default due date and a description is added to the task.The default due date is
    July 1, 2009.

    C#VB複製
     public override void ItemAdded(SPItemEventProperties properties){    base.ItemAdded(properties);    SPWeb web = properties.OpenWeb();    properties.ListItem["Due Date"] = "July 1, 2009";    properties.ListItem["Description"] = "This is a critical task.";    properties.ListItem.Update(); }  
Customizing the Project Task List Feature

When you create a SharePoint solution, Visual Studio automatically creates features for the default project items.You can customize the project task list settings for the SharePoint
site by using the Feature Designer.

To customize the project task list feature
  1. In Solution Explorer, expand
    Features.

  2. Double click Feature1.

  3. In the Title field, type
    Project Task List Feature.

  4. In the Scope drop-down menu, select
    Web.

  5. In the Properties window, type
    1.0.0.0 as the value for the Version property.

Customizing the Project Task List Package

When you create a SharePoint project, Visual Studio automatically adds the features that contain the default project items to the package.You can customize the project task list settings
for the SharePoint site by using the Package Designer.

To customize the project task list package
  1. In SolutionExplorer, double-click
    Package.

  2. In the Name field, type
    ProjectTaskListPackage.

  3. Select Reset WebServer.

Building and Testing the Project Task List

When you run the project, the SharePoint site opens.However, you must manually navigate to the location of the task list.

To test the project task list
  1. Press F5 to build and deploy your project task list.

    The SharePoint site opens.

  2. Click Home.

  3. In the left sidebar, click
    ProjectTaskList - ListInstance1.

    The Project Task List page appears.

  4. In the List Tools tab, click
    Items.

  5. Click New Item.

  6. Click Task.

  7. In the Title text box, type Task1.

  8. Click Save.

    After the site is refreshed, the
    Task1 task appears with a due date of 7/1/2009.

  9. Click Task1.

    The detailed view of the task appears, and the description shows "This is a critical task."

Deploying the Project Task List

After you build and test the project task list, you can deploy it to the
local system or a remote system.The local system is the same computer on which you developed the solution, whereas a remote system is a different computer.

To deploy the project task list to the local system
  • Click Deploy on the
    Build menu.

    Visual Studio recycles the IIS application pool, retracts any existing versions of the solution, copies the solution package (.wsp) file to SharePoint, and then activates its features.You
    can now use the solution in SharePoint.For more information about deployment configuration steps, see
    How to: Edit a SharePoint Deployment Configuration.

To deploy the project task list to a remote system
  1. Click Package on the
    Build menu.

    This creates a .wsp file for the solution in your project’s binary debug folder (…\<Project Name>\<Project Name>\bin\Debug).

  2. Copy the .wsp file to the remote SharePoint system.

  3. Use the PowerShell Add-SPUserSolution command to install the package on the remote SharePoint installation.(For farm solutions, use the
    Add-SPSolution command.)

    For example, Add-SPUserSolution C:\MyProjects\ProjectTaskList\ProjectTaskList\bin\Debug\ProjectTaskList.wsp.

  4. Use the PowerShell Install-SPUserSolution command to deploy the solution.(For farm solutions, use the
    Install-SPSolution command.)

    For example, Install-SPUserSolution –Identity ProjectTaskList.wsp –Site http://NewSiteName.

    For more information about remote deployment, see
    Using Solutions and
    Adding and Deploying Solutions with PowerShell in SharePoint 2010.

Next Steps

You can learn more about how to customize and deploy SharePoint solutions from the following topics:

  • Walkthrough: Create a Custom Field, Content Type, List Definition, and List Instance

  • How to: Create an Event Receiver

  • Windows PowerShell for SharePoint Server 2010

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.