How To: Create a Sample Workspace Instance Site Using Visual Studio 2010

Learn how to create a Duet Enterprise for Microsoft SharePoint and SAP workspace that interacts with external systems by using Microsoft Visual Studio 2010.

Applies to: Duet Enterprise for Microsoft SharePoint and SAP Server 2.0 | Office 2010 | SharePoint Server 2010

In this article
Overview: Steps to Create the Sample Workspace Site Template
Creating a Site Definition Project for the Sample Workspace Site
Creating a Module Feature Element That Contains a Default Page
Adding the Business Data Item Web Part to the Default Page
Adding a List Instance to the Site Definition
Adding a Reports Library to the Site Definition
Adding Code for the Feature Event Receiver
Building and Deploying the SharePoint 2010 Solution Package

You can use Microsoft Visual Studio 2010 to create workspaces that interact with external systems. The procedures in this topic demonstrate how to create a site template for displaying sales orders by using Visual Studio 2010. The external system used in this case is a sales order entity from SAP that is exposed through the Business Data Connectivity (BDC) service. When you have completed the procedures in this topic, you will have created a site that looks resembles the site shown in Figure 1

Figure 1. Sales order instance site

Sales order instance site

Overview: Steps to Create the Sample Workspace Site Template

The following are the steps to create the sample workspace site template that will display sales orders:

  1. Create a site definition.

  2. Add a Module element that contains a default page.

  3. Add a Business Data Item Web Part to the default page.

  4. Add a list instance to the site definition.

  5. Add a Reports Library to the site definition.

  6. Add code for the feature event receiver.

  7. Build and deploy the SharePoint solution package (.wsp) file that contains the site definition.

Creating a Site Definition Project for the Sample Workspace Site

The steps in the following procedure describe how to create a site definition project in Visual Studio 2010 for the sample workspace site.

To create a new site definition project

  1. Start Visual Studio 2010 by using the Run as Administrator option.

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

  3. In the New Project dialog box, expand the Visual C# node, expand the SharePoint node, and then select the 2010 node.

  4. In the Templates pane select Site Definition, name the solution, and then click OK. The SharePoint Customization Wizard opens. This wizard enables you to select the site that you want to use to debug the project and the trust level of the solution.

  5. In the SharePoint Customization Wizard, type the name of the local site you want to use for debugging, click Deploy as farm solution, and then click Finish to accept the default local SharePoint site.

Creating a Module Feature Element That Contains a Default Page

The steps in the following procedure describe how to create a Module Feature element that contains a default page.

To add the default module

  1. In Solution Explorer, right-click the project, click Add, and then click New item.

  2. In the Add New Item dialog box, expand Visual C#, expand SharePoint, expand 2010, and then click Module.

  3. Name the module Default, and then click Add, as shown in Figure 2.

    Figure 2. Add a module to a site definition project

    Add a module to a site definition project

  4. In Solution Explorer, under Default, delete the sample.txt file.

  5. Move the default.aspx page from Site Definition to Default.

  6. Under Default, click default.aspx, and then click F4 to open the Properties pane.

    In the Properties pane, expand the Deployment Location, as shown in Figure 3.

    Figure 3. Set values for the deployment location

    Set values for the deployment location

    If it is not already set, set the Root as {SharePointRoot}\Template\Features\{FeatureName}\.

  7. Set the Path as a blank/empty string.

  8. Under Default, open default.aspx and replace the contents of default.aspx with the following code.

    <%@ Page language="C#" MasterPageFile="~masterurl/default.master" Inherits="Microsoft.SharePoint.WebPartPages.WebPartPage,Microsoft.SharePoint,Version=14.0.0.0,
    Culture=neutral,PublicKeyToken=71e9bce111e9429c"  %>
    <%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" 
    Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" 
    Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, 
    Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
    <%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" 
    Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Import Namespace="Microsoft.SharePoint" %>
    <%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>
    <%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    
    <asp:Content ContentPlaceHolderId="PlaceHolderPageTitle" runat="server">
        <SharePoint:ProjectProperty Property="Title" runat="server"/>
    </asp:Content>
    
    <asp:Content ID="Content1" ContentPlaceHolderId="PlaceHolderMain" runat="server">
    
         <table cellpadding="4" cellspacing="0" border="0" width="100%">
            <tr>
                <td valign="top" height="100%">
                    <WebPartPages:WebPartZone runat="server" Title="ZoneLeft" ID="Left" FrameType="TitleBarOnly" />
                </td>
                <td valign="top" height="100%" width="100%">
                    <WebPartPages:WebPartZone runat="server" Title="ZoneRight" ID="Right" FrameType="TitleBarOnly" />
                </td>      
            </tr>
        </table>
    
    </asp:Content>
    

    This code adds two Web Part zones. You will place your Web Parts in these two zones.

  9. Save all files.

Adding the Business Data Item Web Part to the Default Page

The two procedures in this section describe how to add the Business Data Item Web Part to the default page that you created in the previous step. To add this Web Part, you will do the following:

  1. Export the Business Data Item Web Part definition.

  2. Add the Business Data Item Web Part definition to the default page.

To export the Business Data Item Web Part definition

  1. Open your browser, and then navigate to the home page of your Duet Enterprise site.

  2. On the Site Actions menu, click Edit Page, and then click the Page tab on the Server ribbon, as shown in Figure 4.

    Figure 4. Select edit page option from the ribbon

    Select edit page option from the Ribbon

  3. On the Edit Page, click Add a Web Part. Under the Categories column, click Business Data.Then, under the Web Parts menu, click Business Data Item. Click Add.

    Figure 5. Select the Business Data Item Web Part

    Select the Business Data Item Web Part

  4. Click Open the Tool Pane, as shown in Figure 6.

    Figure 6. Open the Business Data Item Web Part tool pane

    Open the Business Data Item Web Part tool pane

  5. Click the Entity Picker, which is highlighted by the red box in Figure 7.

    Figure 7. Select the Entity Picker

    Select the Entity Picker

  6. Select the Sales Order Entity, and then click OK. In the dialog box that opens, in the Fields category, click Choose.

  7. Select the fields that you want to appear in the Business Data Item Web Part, as shown in Figure 8, and then click OK.

    Figure 8. Select fields for the Business Data Item Web Part

    Select fields for the Business Data Item Web Part

  8. Click OK on the Business Data Item Web Part tool pane.

  9. On the drop-down menu that appears in the upper right of the Web Part zone to which you added the Business Data Item Web Part, click Export, as shown in Figure 9.

    Figure 9. Export the Business Data Item Web Part

    Export the Business Data Item Web Part

  10. Provide the file name of the Business Data Item Web Part definition and specify the file path where you want to save the Business Data Item Web Part definition.

  11. On the Page tab on the ribbon, click Stop Editing.

To add the Business Data Item Web Part to the default page

  1. In Solution Explorer, under Default, open Elements.xml.

  2. Add the Business Data Item Builder Web Part and the Sales Order Item Details Web Part (which will contain the Business Data Item Web Part definition), and a connection string for the Sales Order Item Details Web Part, to the Elements.xml file. You do this by adding two AllUsersWebPart elements in the appropriate location, as shown in the following example.

    <?xml version="1.0" encoding="utf-8"?>
    <Elements xmlns="https://schemas.microsoft.com/sharepoint/">
        <Module Name="Default" Url="" Path="" xmlns="https://schemas.microsoft.com/sharepoint/">
          <File Path="default.aspx" Url="default.aspx" >
    
          <WebPartConnection ID="Connection1" ConsumerID="SalesOrderItemDetails" 
          ProviderID="BusinessDataItemBuilder" ConsumerConnectionPointID="BDWP Item"
          ProviderConnectionPointID="BDWP Item" />
            <AllUsersWebPart ID="BusinessDataItemBuilder" WebPartOrder="0" WebPartZoneID="Left">
              <![CDATA[ 
    
                        <WebPart xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="https://schemas.microsoft.com/WebPart/v2">
                          <Title>Business Data Item Builder</Title>
                          <FrameType>Default</FrameType>
                          <Description>Creates a Business Data Item from parameters in 
                            the query string and provides it to other Web Parts.</Description>
                          <IsIncluded>true</IsIncluded>
                          <ZoneID>Header</ZoneID>
                          <PartOrder>0</PartOrder>
                          <FrameState>Normal</FrameState>
                          <Height />
                          <Width />
                          <AllowRemove>true</AllowRemove>
                          <AllowZoneChange>true</AllowZoneChange>
                          <AllowMinimize>true</AllowMinimize>
                          <AllowConnect>true</AllowConnect>
                          <AllowEdit>true</AllowEdit>
                          <AllowHide>true</AllowHide>
                          <IsVisible>true</IsVisible>
                          <DetailLink />
                          <HelpLink />
                          <HelpMode>Modeless</HelpMode>
                          <Dir>Default</Dir>
                          <PartImageSmall>/_layouts/images/bizdatawebpart.gif</PartImageSmall>
                          <MissingAssembly />
                          <PartImageLarge>/_layouts/images/bizdatawebpart.gif</PartImageLarge>
                          <IsIncludedFilter />
                          <Hidden>false</Hidden>
                          <AuthorizationFilter>
                          </AuthorizationFilter>
                          <Assembly>Microsoft.SharePoint.Portal, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
                          <TypeName>Microsoft.SharePoint.Portal.WebControls.BusinessDataItemBuilder</TypeName>
                        </WebPart>
                     ]]>
            </AllUsersWebPart>
            </AllUsersWebPart>
    
             <AllUsersWebPart ID="SalesOrderItemDetails" WebPartOrder="1" WebPartZoneID="Left">
                   <![CDATA[
    
          ]]>
            </AllUsersWebPart>
    
    
          </File>
    </Module>
    </Elements>
    

    Note

    The Business Data Item Builder Web Part is a hidden Web Part that provides access to a Business Data Item to other Web Parts on the page.

  3. Open the Business Data Item Web Part definition that you saved in the previous procedure. Copy all of the contents of this file into the CDATA section that you created for the Sales Order Item Details Web Part in the previous step. The following example shows how the XML for the Sales Order Item Details Web Part will look after you add the Business Data Item Web Part definition.

    <AllUsersWebPart ID="SalesOrderItemDetails" WebPartOrder="1" WebPartZoneID="Left">
    <![CDATA[
    <webParts>
      <webPart xmlns="https://schemas.microsoft.com/WebPart/v3">
        <metaData>
          <type name="Microsoft.SharePoint.Portal.WebControls.BusinessDataDetailsWebPart,
       Microsoft.SharePoint.Portal, Version=14.0.0.0, Culture=neutral, 
       PublicKeyToken=71e9bce111e9429c" />
          <importErrorMessage>Cannot import this web part.</importErrorMessage>
        </metaData>
        <data>
          <properties>
            <property name="ChromeType" type="chrometype">Default</property>
            <property name="ShowWithSampleData" type="bool">False</property>
            <property name="XmlDefinitionLink" type="string" />
            <property name="Default" type="string" />
            <property name="NoDefaultStyle" type="string">TRUE</property>
            <property name="LobSystemInstanceName" type="string">SalesOrder</property>  
            <property name="ViewContentTypeId" type="string" />
            <property name="EntityId" type="System.Int64, mscorlib, Version=2.0.0.0, 
             Culture=neutral, PublicKeyToken=b77a5c561934e089">11103</property>
    
            <property name="ViewFlags" type="Microsoft.SharePoint.SPViewFlags, 
             Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral,
             PublicKeyToken=71e9bce111e9429c">None</property>
          <property name="ExportMode" type="exportmode">All</property>
            <property name="ListId" type="System.Guid, mscorlib, Version=2.0.0.0, Culture=neutral,
          PublicKeyToken=b77a5c561934e089">00000000-0000-0000-0000-000000000000</property>
            <property name="AutoRefreshInterval" type="int">60</property>
            <property name="AllowEdit" type="bool">True</property>
            <property name="Description" type="string">Displays one item from 
             a data source in Business Data Connectivity.</property>
    
            <property name="Xsl" type="string">&lt;xsl:stylesheet version="1.0" 
             exclude-result-prefixes="xsl msxsl ddwrt" 
             xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
             xmlns:ddwrt="https://schemas.microsoft.com/WebParts/v2/DataView/runtime"
             xmlns:asp="https://schemas.microsoft.com/ASPNET/20" 
             xmlns:msxsl="urn:schemas-microsoft-com:xslt"
             xmlns:SharePoint="Microsoft.Sharepoint.WebControls"&gt;
              &lt;xsl:output method="html" indent="no" /&gt;
    
    
       <property name="ChromeState" type="chromestate">Normal</property>
            <property name="CatalogIconImageUrl" type="string">/_layouts/images/bizdatawebpart.gif</property>
    
            <property name="Fields" 
             type="System.Collections.Generic.List`1[[System.String, mscorlib, Version=2.0.0.0,
             Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, 
             Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">&lt;?xml version="1.0"
             encoding="utf-8"?&gt;
              &lt;ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
            &lt;string&gt;SalesOrderTypeCode&lt;/string&gt;
            &lt;string&gt;SoldToPartyDesc&lt;/string&gt;
            &lt;string&gt;BillToPartyDesc&lt;/string&gt;
    
    
              &lt;/ArrayOfString&gt;</property>
            <property name="Width" type="string" />
            <property name="UseSQLDataSourcePaging" type="bool">True</property>
            <property name="DeselectedActions" 
             type="System.Collections.Generic.List`1[[System.String, mscorlib, 
             Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib,
             Version=2.0.0.0, Culture=neutral, 
             PublicKeyToken=b77a5c561934e089">&lt;?xml version="1.0" encoding="utf-8"?&gt;
              &lt;ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
              &lt;/ArrayOfString&gt;</property>
            <property name="PageType" type="Microsoft.SharePoint.PAGETYPE, Microsoft.SharePoint,
             Version=14.0.0.0, Culture=neutral,
             PublicKeyToken=71e9bce111e9429c">PAGE_NORMALVIEW</property>
            <property name="DataSourcesString" 
                type="string">&lt;%@ Register TagPrefix="cc1" 
                Namespace="Microsoft.SharePoint.WebControls" 
                Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral,
                PublicKeyToken=71e9bce111e9429c" %&gt;&lt;cc1:BdcDataSource runat="server"
                UpdateCommand="" ShowSampleData="False" Mode="Item" 
                EntityName="SalesOrder" Enabled="True" EntityId="0"
                EntityNamespace="SAP.Office.DuetEnterprise.SalesOrder" 
                LobSystemInstanceName="SalesOrder" InsertCommand="" DeleteCommand=""
             SelectCommand=""&gt;&lt;/cc1:BdcDataSource&gt;
            </property>
            <property name="InitialAsyncDataFetch" type="bool">False</property>
    
            <property name="SelectedActions"
             type="System.Collections.Generic.List`1[[System.String, mscorlib, Version=2.0.0.0,
             Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, 
             Version=2.0.0.0, Culture=neutral, 
             PublicKeyToken=b77a5c561934e089">&lt;?xml version="1.0" encoding="utf-8"?&gt;
              &lt;ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
             xmlns:xsd="http://www.w3.org/2001/XMLSchema" &gt;
              &lt;/ArrayOfString&gt;</property>        
            <property name="ParameterBindings" type="string" null="true" />
    
          </properties>
        </data>
      </webPart>
    </webParts>
    
    ]]>
            </AllUsersWebPart>
    

Adding a List Instance to the Site Definition

The procedure in this section describes how to add a list instance to the site definition. This specific example demonstrates how to add a Discussion Board to the site and a Discussion Board view to the default page.

To add a list instance to the site definition

  1. In Solution Explorer, right-click the project, click Add, and then click New item. In the Add New Item dialog box, click List Instance.

  2. Name the List Discussion, and then click Add, as shown in Figure 10.

    Figure 10. Create a list instance in Visual Studio 2010

    Create a list instance in Visual Studio 2010

  3. In the SharePoint Customization Wizard, for Which list do you want instantiate?, select Discussion Board, and then click Finish, as shown in Figure 11.

    Figure 11. List instance settings

    List instance settings

  4. In Solution Explorer, under Default, open Elements.xml. Add the View element to the appropriate location, as shown in the following example.

    <?xml version="1.0" encoding="utf-8"?>
    <Elements xmlns="https://schemas.microsoft.com/sharepoint/">
        <Module Name="Default" Url="" Path="" xmlns="https://schemas.microsoft.com/sharepoint/">
          <File Path="default.aspx" Url="default.aspx" >
    
       <WebPartConnection ID="Connection1" ConsumerID="SalesOrderItemDetails" ProviderID="BusinessDataItemBuilder" ConsumerConnectionPointID="BDWP Item" ProviderConnectionPointID="BDWP Item" />
    
    
    
            <AllUsersWebPart ID="BusinessDataItemBuilder" WebPartOrder="0" WebPartZoneID="Left">
    …..
            </AllUsersWebPart>
    
    <AllUsersWebPart ID="SalesOrderItemDetails" WebPartOrder="1" WebPartZoneID="Left">
    …….
            </AllUsersWebPart>
    
            <!-- Team Discussion web part-->
    <View List="Lists/Discussion" BaseViewID="3" WebPartOrder="2" WebPartZoneID="Right" />
    
    
          </File>
    </Module>
    </Elements>
    
  5. Save all files in the Visual Studio 2010 project.

Adding a Reports Library to the Site Definition

The procedure in this section describes how to add a reports library to the site definition and a Reports Library view to the default page.

To add a reports library to the site definition

  1. In Solution Explorer, under Site Definition, open onet.xml. Add the Reporting feature ID to the WebFeatures element, as shown in the following example.

    Note

    This will add the reports library to the site if the Reporting feature is activated.

    <?xml version="1.0" encoding="utf-8"?>
    <Project Title="DuetInstanceSiteDefintion1" Revision="2" ListDir="" xmlns:ows="Microsoft SharePoint" xmlns="https://schemas.microsoft.com/sharepoint/">
      <NavBars>
      </NavBars>
      <Configurations>
        <Configuration ID="0" Name="DuetInstanceSiteDefintion1">
          <Lists/>
          <SiteFeatures>
          </SiteFeatures>
          <WebFeatures>
            <!--Report Doc Lib-->
            <Feature ID="70F4688E-86F0-47f3-8894-0DED858BDFEE " />
          </WebFeatures>
          <Modules>
          </Modules>
        </Configuration>
      </Configurations>
      <Modules>
       </Modules>
    </Project>
    
  2. In Solution Explorer, under Default, open Elements.xml. Add the reports library View element to the appropriate location, as shown in the following example.

    <?xml version="1.0" encoding="utf-8"?>
    <Elements xmlns="https://schemas.microsoft.com/sharepoint/">
        <Module Name="Default" Url="" Path="" xmlns="https://schemas.microsoft.com/sharepoint/">
          <File Path="default.aspx" Url="default.aspx" >
    
       <WebPartConnection ID="Connection1" ConsumerID="SalesOrderItemDetails" ProviderID="BusinessDataItemBuilder" ConsumerConnectionPointID="BDWP Item" ProviderConnectionPointID="BDWP Item" />
    
    
    
            <AllUsersWebPart ID="BusinessDataItemBuilder" WebPartOrder="0" WebPartZoneID="Left">
    …..
            </AllUsersWebPart>
    
    <AllUsersWebPart ID="SalesOrderItemDetails" WebPartOrder="1" WebPartZoneID="Left">
    …….
            </AllUsersWebPart>
    
    
    <!-- Reports List View-->
          <View List="ReportsLib" DisplayName="" DefaultView="FALSE" BaseViewID="1" Type="HTML" 
    Scope="Recursive" WebPartOrder="5" WebPartZoneID="Left” 
    ID="g_22e46c7b_3088_43c5_bccf_b41919737fab" Hidden="TRUE">
          </View>
    
    
          </File>
    </Module>
    </Elements>
    
  3. Save all files in the Visual Studio 2010 project.

Adding Code for the Feature Event Receiver

The procedure in this section describes how to add the code for the FeatureActivated event receiver that must run when you deploy the site definition in your Visual Studio 2010 project. This code optimizes the presentation of business data in your new Business Data Item Web Part.

To add the feature event receiver code

  1. In Solution Explorer, under Features, Feature1, right-click Feature1.feature, and then click Add Event Receiver.

  2. Copy the following code into the Feature1.EventReceiver.cs file.

    internal static class Constants
        {
            internal const string WebPartZoneID1 = "Left";
            internal const string WebPartZoneID2 = "Right";
            internal const string DefaultPage = "default.aspx";
    
    
        }
    
            [Microsoft.SharePoint.Security.SharePointPermission(SecurityAction.LinkDemand, ObjectModel = true)]
            public override void FeatureActivated(SPFeatureReceiverProperties properties)
            {
    
    
                base.FeatureActivated(properties);
    
                try
                {
                    SPWeb centerWeb = (SPWeb)properties.Feature.Parent;
                    uint currentLCID = centerWeb.Language;
    
    
                    // Set site description.
                    centerWeb.Description = " instance site description";
    
                    SPFile file = centerWeb.GetFile(SPUrlUtility.CombineUrl(centerWeb.Url, Constants.DefaultPage));
    
    
                    using (SPLimitedWebPartManager webPartManager = file.GetLimitedWebPartManager(PersonalizationScope.Shared))
                    {
    
                        // Replace 'Team Discussion' Web Part.
    
                        string teamDiscussionListTitle = "Team Discussion";
    
                        SPList teamDiscussionList = centerWeb.Lists[teamDiscussionListTitle];
    
                        XsltListViewWebPart initialTDWebPart = GetXsltListViewWebPart(webPartManager, teamDiscussionListTitle);
    
                        if (initialTDWebPart != null)
                        {
                            webPartManager.DeleteWebPart(initialTDWebPart);
                        }
    
                        XsltListViewWebPart teamDiscussionListWebPart = new XsltListViewWebPart();
    
                        teamDiscussionListWebPart.Title = teamDiscussionListTitle;
                        teamDiscussionListWebPart.ListName = teamDiscussionList.ID.ToString("B").ToUpper(CultureInfo.InvariantCulture);
    
                        webPartManager.AddWebPart(teamDiscussionListWebPart, Constants.WebPartZoneID1, 20);
    
    
                        file.Update();
                    };
    
                    centerWeb.Update();
                    }
                catch (Exception e)
                {
                    throw;
                }
    
            }
    
    
    
            internal static XsltListViewWebPart CreateXsltListViewWebPart(SPList list, string listTitle)
            {
    
                XsltListViewWebPart listWebPart = new XsltListViewWebPart();
    
                listWebPart.Title = listTitle;
                listWebPart.ListName = list.ID.ToString("B").ToUpper(CultureInfo.InvariantCulture);
                listWebPart.ViewGuid = list.Views[0].ID.ToString();
                return listWebPart;
            }
    
            static XsltListViewWebPart GetXsltListViewWebPart(SPLimitedWebPartManager webPartManager, string listTitle)
            {
                XsltListViewWebPart listViewWebPart = null;
    
                foreach (Microsoft.SharePoint.WebPartPages.WebPart xlvwp in webPartManager.WebParts)
                {
                    if (String.Equals(xlvwp.Title, listTitle))
                    {
                        listViewWebPart = (XsltListViewWebPart)xlvwp;
                        break;
                    }
                }
                return listViewWebPart;
            }
    
  3. In Solution Explorer, right-click References, and then click Add Reference. On the .Net tab, click System.Web, and then click OK.

  4. Add the following code declarations to Feature1.EventReceiver.cs.

    using Microsoft.SharePoint.Utilities;
    using Microsoft.SharePoint.WebPartPages;
    using System.Web.UI.WebControls.WebParts;
    using System.Globalization;
    
  5. Save all files in the project.

  6. Double-click Feature1.feature, and then press F4 to display the Properties pane.

  7. Copy the feature ID from the feature properties.

  8. Under Site Definition, right-click Onet.xml, and then click Open. Replace the feature ID in Onet.xml with your feature ID, as shown in the following example.

    <?xml version="1.0" encoding="utf-8"?>
    <Project Title="DuetCenterSiteDefintion1" Revision="2" ListDir="" xmlns:ows="Microsoft SharePoint" xmlns="https://schemas.microsoft.com/sharepoint/">
      <NavBars>
      </NavBars>
      <Configurations>
        <Configuration ID="0" Name="DuetCenterSiteDefintion1">
          <Lists/>
          <SiteFeatures>
          </SiteFeatures>
          <WebFeatures>
            <Feature ID="fe1351f1-49c6-475b-8ff6-3f285937c169" />
            <!--Report Doc Lib-->
            <Feature ID="70F4688E-86F0-47f3-8894-0DED858BDFEE" />
          </WebFeatures>
          <Modules>
          </Modules>
        </Configuration>
      </Configurations>
      <Modules>
       </Modules>
    
  9. In Solution Explorer, under Features, Feature1, double-click Feature1.feature. Expand Feature activation dependencies, and then click Add a custom dependency.

  10. Provide 70F4688E-86F0-47f3-8894-0DED858BDFEE as the reporting library Feature ID. Figure 12 shows the feature activation dependencies.

    Figure 12. Feature activation dependencies

    Feature activation dependencies.

  11. Click Add, and then save all files in the project.

Building and Deploying the SharePoint 2010 Solution Package

The procedure in this section describes how to build and deploy the SharePoint 2010 solution package that contains the site definition for the sample workspace.

To build and deploy the solution package

  1. In Solution Explorer, right-click the project, and then click Deploy.

  2. In your SharePoint site, click Site actions, and then click new site.

  3. The new site template appears under SharePoint Customization. Select the template, provide the site title and URL name, and then click Create. The Sales Order workspace center site appears.

  4. Navigate to the default page, and then add SalesOrderHeaderId=1 to the query string of the URL. The resulting URL will look like http://site/SalesOrderInstance/default.aspx?SalesOrderHeaderId=1. The Sales Order workspace center will display sales data, as shown in Figure 13.

    Figure 13. View sales order instance site

    View sales order instance site

See Also

Concepts

How To: Create a Workspace Center Site Using Visual Studio 2010