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

Learn how to create a sample workspace center by using the Duet Enterprise and Microsoft Visual Studio 2010.

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

In this article
Steps to Create the Workspace Center
Creating a Site Definition Project for the Workspace Center Site
Adding the External List to the Workspace Center
Creating a Module Feature Element That Contains a Default Page
Adding Code for the Feature Event Receiver
Building and Deploying the 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 resembles the site shown in Figure 1.

Figure 1. Sales order center site

Sales order center site

Steps to Create the Workspace Center

The following are the steps to create the workspace center:

  1. Create the site definition.

  2. Add an external list.

  3. Add a module feature element that contains the default page.

  4. Add code for the feature receiver.

  5. Build the solution package (.wsp) file that contains the site definition.

Creating a Site Definition Project for the Workspace Center Site

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

To create a site definition project

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

  2. On the File menu, click New, and then click 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 appears. This wizard enables you to select the site 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 to use for debugging, click Deploy as farm solution, and then click Finish to accept the default local SharePoint site.

Adding the External List to the Workspace Center

The steps in the following procedure describe how to add an external list to the workspace center.

To add the external list

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

  2. In the Add New Item dialog box, click List Instance.

  3. Name the list instance Sales Order, and then click Add.

  4. In the SharePoint Customization Wizard, in Which list do you want instantiate?, click Custom List, and then click Finish.

    Note

    For simplicity, this example uses Custom List. You can select any list, because the contents of the list will be replaced in a later step.

  5. In Solution Explorer, right-click SalesOrder, click Add, and then click New Item.

  6. In the Add New Item dialog box, in the Installed Templates pane, click Data, and then click XML File.

  7. Name the XML file ExternalListSchema.xml, and then click Add.

  8. In Solution Explorer, under SalesOrder, click ExternalListSchema.xml, and then press F4 to display the Properties pane.

  9. In the list of properties, click Deployment Type, and then select the ElementFile deployment type.

  10. Expand Deployment Location.

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

  12. Set the Path property as a blank/empty string.

  13. In Solution Explorer, open Elements.xml under SalesOrder. Replace Elements.xml with the following markup.

    <?xml version="1.0" encoding="utf-8"?>
    <Elements xmlns="https://schemas.microsoft.com/sharepoint/">
      <ListInstance Title="SalesOrder"
                    OnQuickLaunch="TRUE"
                    TemplateType="600"
                    FeatureId="00bfea71-de22-43b2-a848-c05709900100"
                    Url="Lists/Salesorder"
                    Description="SalesOrder finder"
                    CustomSchema="ExternalListSchema.xml"
                    xmlns="https://schemas.microsoft.com/sharepoint/">
          <DataSource>
            <Property Name="Entity" Value="SalesOrder" />
            <Property Name="EntityNamespace" Value="http://duetsrv-01-vm01/" />
            <Property Name="LobSystemInstance" Value="SalesOrder" />
            <Property Name="SpecificFinder" Value="FindSalesOrderById" />
          </DataSource>
        </ListInstance>
    </Elements>
    
  14. Update the values for Entity, EntityNamespace, LobSystemInstance, and SpecificFinder so that they match the values in the BDC model.

  15. Under SalesOrder, open ExternalListSchema.xml.

  16. Replace the contents of ExternalListSchema.xml with following markup.

    <?xml version="1.0" encoding="utf-8"?>
    <List Title="SalesOrder" Url="Lists/SalesOrder ">
      <MetaData>
        <Views>
          <View BaseViewID="1" Type="HTML" WebPartZoneID="Main" DisplayName="Sales Order DN"
                DefaultView="TRUE" MobileView="True" MobileDefaultView="False" SetupPath="pages\viewpage.aspx" ImageUrl="/_layouts/images/issues.png"
                Url="AllItems.aspx">
            <XslLink>main.xsl</XslLink>
            <RowLimit Paged="TRUE">100</RowLimit>
            <Toolbar Type="Standard" />
            <ViewStyle ID="17"/>
            <Method Name="FindSalesOrderByElements"/>
               <ViewFields>
              <FieldRef Name="SalesOrderHeaderID"/>
              <FieldRef Name="SalesOrderDesc"/>
              <FieldRef Name="SalesOrderType"/>
            </ViewFields>
            <Query>
             <OrderBy>
              <FieldRef Name="SalesOrderHeaderID"/>
             </OrderBy>
            </Query>
            <Aggregations Value="Off"/>
          </View>
        </Views>
        <Forms>
          <Form Type="DisplayForm" Url="DispForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" />
        </Forms>
      </MetaData>
    </List>  
    

    Note

    The values for the Title attribute and Url attribute of the List element should match the ones used for the same attributes of the ListInstance element in the Elements.xml file. Also, the values of the Name attributes of the FieldRef child elements of the ViewFields element should be return parameters of the method that is defined by the Method element.

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, click Visual C#, click SharePoint, click 2010, and then click Module.

  3. Name the module Default, and then click Add.

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

  5. Replace the content of Elements.xml with the following markup.

    <?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 Url="default.aspx" NavBarHome="True">      
          <View List="Lists/SalesOrder"
          BaseViewID="1" WebPartZoneID="ZoneLeft"
          WebPartOrder="0" />
        </File>
      </Module>
    </Elements>
    
  6. In Solution Explorer, under Default, delete the sample.txt file.

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

  8. Under Default, click default.aspx, and press F4 to open the Properties pane.

    In the Properties pane, expand the Deployment Location.

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

  9. Set the Path as Blank/Empty string.

  10. Under Default, open Default.aspx and replace the content with the following markup.

    <%@ 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">
        <h1>
            Welcome to the Sales Order Center Site
        </h1>
        <table cellpadding="4" cellspacing="0" border="0" width="100%">
            <tr>
                <td valign="top" height="100%">
                    <WebPartPages:WebPartZone runat="server" Title="ZoneLeft" ID="ZoneLeft" FrameType="TitleBarOnly" />
                </td>          
            </tr>
        </table>
    
    </asp:Content>
    

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

  11. 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 is required to run when you deploy the site definition in your Visual Studio 2010 project.

To add the feature event receiver code

  1. In Solution Explorer, under the Features node, expand the Feature1 node, 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 LeftZoneWebPartZoneID = "ZoneLeft";
            //internal const string LeftWebPartZoneID = "Left";
            internal const string DefaultPage = "default.aspx";
            internal const string Entity = "Entity";
            internal const string EntityNamespace = "EntityNamespace";
            internal const string ShowInECBtrue = "ShowInECB=true";
            internal const string ListActionName = "BDC.URL.{0}";
    
        }
    
             [Microsoft.SharePoint.Security.SharePointPermission(SecurityAction.LinkDemand, 
    ObjectModel = true)]
            public override void FeatureActivated(SPFeatureReceiverProperties properties)
            {
    
                if (properties == null)
                {
                    throw new System.ArgumentNullException("properties");
                }
    
                base.FeatureActivated(properties);
    
                try
                {
                    SPWeb centerWeb = (SPWeb)properties.Feature.Parent;
                    uint currentLCID = centerWeb.Language;
    
                    SPFile file = centerWeb.GetFile(SPUrlUtility.CombineUrl(centerWeb.Url, Constants.DefaultPage));
    
                    string externalListTitle = "SalesOrder";
                    SPList externalList = centerWeb.Lists[externalListTitle]; // SalesOrder list created from element manifest of dependent feature
                    externalList.OnQuickLaunch = true;
                    externalList.Update();
    
                    using (SPLimitedWebPartManager webPartManager = file.GetLimitedWebPartManager(PersonalizationScope.Shared))
                    {
                        XsltListViewWebPart initialWebPart = GetXsltListViewWebPart(webPartManager, externalListTitle);
                        XsltListViewWebPart externalListWebPart = CreateXsltListViewWebPart(externalList, externalListTitle);
                        webPartManager.AddWebPart(externalListWebPart, Constants.LeftZoneWebPartZoneID, 0);
    
                        if (null != initialWebPart)
                        {
                            webPartManager.DeleteWebPart(initialWebPart);
                        }
                        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;
            }
    
            internal 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-3f280000000" />
          </WebFeatures>
          <Modules>
          </Modules>
        </Configuration>
      </Configurations>
      <Modules>
       </Modules>
    

Building and Deploying the Solution Package

The procedure in this section describes how to build and deploy the project as a 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.

    The new site template will appear under SharePoint Customization.

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

See Also

Concepts

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