Dotnetdreamer's Weblog

SharePoint, Silverlight and Azure

Posts Tagged ‘Sharepoint 2007’

Creating Lists using Sharepoint Object Model

Posted by Ramprasad Navaneethakrishnan on May 26, 2009

In my previous post I wrote about creating sites using sharepoint object model. I strongly recommend to read that post before proceeding with this. It discusses about Sharepoint Site Architectures in detail.

Listed below are the Sharepoint site components and their corresponding object in the sharepoint object model.

Sharepoint Site Architecture Component Object in Sharepoint Object Model
Site Collection SPSite
Site SPWeb
List Collection SPListCollection
List SPList
List Field Collection SPFieldCollection
List Field SPField
List Item Collection SPListItemCollection
List Item SPListItem

Steps to create a new Sharepoint List:

  1. Open Visual Studio. Create a new Windows Forms project.
  2. Add a textboxes, one to accept the name of the site collection and another to accept the name of the new site to be created under the site collection.
  3. Add a button that creates the new site.
  4. Add reference to Microsoft.Sharepoint dll. This dll is represented by the name Windows Sharepoint Services in the Add Reference dialog box.
  5. Add the namespace of Microsoft.Sharepoint dll like this.
    • using Microsoft.Sharepoint;
  6. In the button click event, open the site collection.
    • SPSite siteCollection = new SPSite(txtSiteCollectionUrl.Text);
  7. Now open the top level site of the site collection.
    • SPWeb site = siteCollection.OpenWeb();
    • If you want to open a different site under the site collection other than the top level site, you can use the overloaded methods of the OpenWeb() method that accepts the name of the site as argument.
  8. The Lists property present in the SPWeb object will return all the lists that are present in that site as an SPListCollection object
    • SPListCollection listCollection = site.Lists;
  9. In order to add a new list, use the add method of the SPListCollection object.
    • listCollection.Add(“listname”, “list description”, SPListTemplateType.GenericList);
    • Note that the third argument accepts the template in which the list should be created. GenericTemplate represents the custom list. We can choose the template we need from the SPListTemplateType enum.
  10. Close and dispose and the site and site collection
    • site.dispose();
    • siteCollection.close();

The complete code can be found below..

using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.SharePoint;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

SPSite siteCollection;
SPWeb site;

private void btnCreateSite_Click(object sender, EventArgs e)
{

try
{
siteCollection = new SPSite(txtSiteCollection.Text);
site = siteCollection.OpenWeb();
SPListCollection listCollection = site.Lists;

listCollection.Add(txtListName.Text, “list description”, SPListTemplateType.GenericList);
}
catch (Exception)
{ }
finally
{
site.Dispose();
siteCollection.Close();
}
}

}
}

Hope this is useful.

Posted in MOSS 2007 | Tagged: , , , , , , , , , , | 4 Comments »

Creating Sites using Sharepoint Object Model

Posted by Ramprasad Navaneethakrishnan on May 24, 2009

MOSS 2007 provides rich set of API’s that allows developers to programatically accomplish  almost everything that can be done in sharepoint. Sharepoint Object Model comes with 10 different dll’s comprising 30 namespaces.

The aim of this post is to leverage the sharepoint object model in order to create a new sharepoint site programatically.

Before getting into that, lets look at the sharepoint site structure in the following diagram.

SiteArchitecture

Each layer in the above architecture diagram is represented by an object in the sharepoint object model. The object mapping is represented in the following table.

Sharepoint Site Architecture Component Object in Sharepoint Object Model
Site Collection SPSite
Site SPWeb
List Collection SPListCollection
List SPList
List Field Collection SPFieldCollection
List Field SPField
List Item Collection SPListItemCollection
List Item SPListItem

Steps to create a new Sharepoint Site:

  1. Open Visual Studio. Create a new Windows Forms project.
  2. Add a textboxes, one to accept the name of the site collection and another to accept the name of the new site to be created under the site collection.
  3. Add a button that creates the new site.
  4. Add reference to Microsoft.Sharepoint dll. This dll is represented by the name Windows Sharepoint Services in the Add Reference dialog box.
  5. Add the namespace of Microsoft.Sharepoint dll like this.
    • using Microsoft.Sharepoint;
  6. In the button click event, open the site collection.
    • SPSite siteCollection = new SPSite(txtSiteCollectionUrl.Text);
  7. Now open the top level site of the site collection.
    • SPWeb site = siteCollection.OpenWeb();
    • If you want to open a different site under the site collection other than the top level site, you can use the overloaded methods of the OpenWeb() method that accepts the name of the site as argument.
  8. SPWeb object has a property called ‘Webs’ that contains a collection of all the sites present under that site.
  9. Inorder to add a new site, use the following code.
    • site.Webs.Add(txtSiteName.Text, txtSiteName.Text, Convert.ToUInt32(1033),site.WebTemplate, , false,false);
  10. Close and dispose and the site and site collection
    • site.dispose();
    • siteCollection.close();

The complete code can be found in this file.using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.SharePoint;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

SPSite siteCollection;
SPWeb site;

private void btnCreateSite_Click(object sender, EventArgs e)
{

try
{
siteCollection = new SPSite(txtSiteCollection.Text);
site = siteCollection.OpenWeb();
site.Webs.Add(txtSiteName.Text, txtSiteName.Text,
txtSiteName.Text + ” Desc”, Convert.ToUInt32(1033),  site.WebTemplate,
false, false);
}
catch (Exception)
{ }
finally
{
site.Dispose();
siteCollection.Close();
}
}

}
}

Hope this is useful.

Thanks.

Posted in MOSS 2007 | Tagged: , , , , , , | 2 Comments »

Custom Templates – Save Site as a Template

Posted by Ramprasad Navaneethakrishnan on May 9, 2009

In my last post, I explained all the out-of-the-box templates availalble in Sharepoint 2007.  In some cases (say a unique business requirement that needs a site template that doen’t fit in any of the one available out-of-the-box),  the templates available out-of-the-box, cannot be utilized right away. We might want to create a template that is customized to a requirement.

MOSS 2007 lets us create a site that is customized to our requirement and allow as to save and use that site as a template. How? Read further..

Now, I want to create a site template that will have the following elements. To make it very simple, I am having  just the following two elements.

  1. Document Library
  2. Picture Library

No available out-of-the-templates suites this requirement. Hence we build our own template

Creating Template Structure

  1. Go to Site Actions –> Create
  2. Select Site and Workspaces
  3. Give a title to the Site, enter the Url in the corresponding box.
  4. In the Select Templates, select Blank Template under the tab Collaboration
  5. Provide the administrator id and click Ok to create the Blank Site
  6. From the newly created Blank Site, go to Site Actions –> Create
  7. Selecte Document Library in the Libraries and Lists section.
  8. Give the name and decscription for the Docuemnt library and click Ok.
  9. Again goto Site Actions –> Create.
  10. Select Picture Libraries in the Libraries and Lists section.
  11. Enter the name and description for the Picture library. Click Ok.

Now we have created the structure for our template. The next step is creating a Template from this structure

Creating Template

  1. Go to Site Actions –> Site Settings
  2. Select Save as a Template from the section ‘ Look and Feel ‘.
  3. savesiteastemplate1
  4. savesiteastemplate2
  5. Enter the name for the template and the template file name. I am giving the name of  ‘TrainingTemplate’ for both template and the filename.
  6. Note the template file is has an extension of .stp.
  7. Give a short description for the template.
  8. Click Ok to create the template.

Once the template is created, it will be available in the Site templte gallery as shown below.

Now lets create a site based on the template we just created.

  1. Go to Site Actions –> Create
  2. Select Sites and Workspaces.
  3. Now you can see a Customtab in the templates section as shown below
  4. Select the Custom tab. This will show the template ‘TrainingTemplate’ we just created.
  5. Select the template, fill other required details like primary site administrator. Click Ok.
  6. Now the created site will have Document libraries and Picture libraries by default as shown below.

Hope this is useful.

Thanks.

Posted in MOSS 2007 | Tagged: , , , , , , , , , | Leave a Comment »

Form Web Part

Posted by Ramprasad Navaneethakrishnan on May 9, 2009

This post discusses about Form Web Part which is an out-of-the-box web part available with MOSS 2007.  Other out-of-the-box MOSS 2007 webparts are discussed here.

Form Web Part unlike other web parts does not operate alone. Usually this web part is used to provide input to other web parts / lists to act accordingly. For example,

  • Form web part can pass the url / path of an image that is to be displayed in the Picture web part.
  • Form web part can pass the value of the filter to be applied to a column in the sharepoint list.

Let us take one of the examples and discuss in detail.

There is a sharepoint list with the name ‘EmployeeDetails’ with the following columns. Name, Title, Email and Department.  The lists looks something like this

formwebpart-employeedetails

The requirement is, we want to dynamically apply the filter on the Department column. ie, we might want to see employees belonging to department ‘HR’ at one time and employees beloging to department ‘Sales’ another time.

For this, lets Add a Form Web Part to the page.

  1. Go to Site Actions –> Edit Page
  2. Click Add a Web Part
  3. Select Form Web Part from the list of web parts displayed
  4. By default, Form web part contains a  textbox and a ‘Go’ button.
  5. Variety of controls like Labels, check boxes etc can be added to the Form Web Part using the Source Editor present in the tool pane.( A web part’s tool pane can be accessed byclicking Modify Shared Web Part option present in the Edit menu of that web part). For simplicity, lets make use of the default controls available with the Form web part. Now the page looks something like this
  6. formwebpart
  7. Now in the Form Web Part, go to Edit –> Connections –> Provide values to –> Select ‘EmployeeDetails’.  This will open ‘Configure Connection’ dialog box.
  8. formwebpart-configureconnection
  9. Select Column T1 and click next (Note T1 is the name of the textbox in the form web part which you can see from the Source Editor of Form Web Part)
  10. Now a second dialog box appears that lists the columns present in the ‘EmployeeDetails’ list. Select the column for which we need to apply the filter. In our case it is ‘Deparment’ column
  11. formwebpart-configureconnection3
  12. Click Next or Finish to complete the configuration
  13. Now to list employee belonging to the department ‘HR’, enter ‘HR’ in the textbox of form web part and click Go. You can see the filtered EmployeeDetailas as below
  14. formwebpart-result1
  15. To get employees belong to Sales department, enter ‘Salee’ in the Form Web Part to get the needed list like below.
  16. formwebpart-result2

 

Hope this is useful..

Please leave your comments.

Thanks.

Posted in MOSS 2007 | Tagged: , , , , , | 11 Comments »

Changing Site Themes – Sharepoint

Posted by Ramprasad Navaneethakrishnan on May 9, 2009

On my previous posts, I wrote about Out-of-the-box Site templates and Creating custom templates

This post is on ‘Changing the Site Theme’ in a Sharepoint site.

  1. Goto Site Actions –> Site Settings
  2. Under the Look and Feel sections, select Site themes. The page will be shown like below.

 

sitethemes-sitesettings

 

sitethemes

3. On selecting various themes available in the list, a preview of the selected theme is shown on the left side.

4. Select the desired theme and select Ok to apply the theme

Posted in MOSS 2007 | Tagged: , , , , | Leave a Comment »

Introduction to Site Templates

Posted by Ramprasad Navaneethakrishnan on May 9, 2009

Sharepoint 2007 comes with some out-of-the-box site templates that allows Administrators or Information Workers to readily create sites by choosing one of the available templates that suites their requirement.

The out-of-the-box Site Templates available with Sharepoint 2007 are broadly classified into 4 categories as mentioned below.

  1. Collaboration
  2. Meeting
  3. Enterprise
  4. Publishing

Collaboration Templates

  • Team Site:
    • This site is for team members to collaborate on any tasks or projects. To facilitate this type of collaboration, it includes the following webparts
      • Document library : To manage documents associated with the task / project
      • Announcement List : Create / Manage announcements with the project team
      • Discussion Board : A forum to discuss on tasks / issues assocaited with the project
      • Calendar Lists : Keeps track of the various schedules associated with team members / project
      • Task Lists : A list that keeps track of task items assigned against members of the project
      • Links : A single place to keep track of  links to sites that are needed for the project

 

teamsite

  • Blank Site:
    • As the name suggests, its just a blank site with no webparts populated by default. This is a good place for building a fully customized site.

 

blanksite

Document Workspace:

  • This template is suitable for a team documentation project or a team of technical writers where there is a need in creation and modification of common documentation.
  • It has the following webparts associated with it.
    • Document Library
    • Tasks List
    • Links

 

documentworkspace

  • Blog Site:
    • A site for a team or person to post ideas and observations which site visitors can comment to.

Meeting Templates

Basic Meeting:

  • A general purpose meeting template that helps to plan, organize and capture the results of the meeting using the following webparts associated with the site
    • Objectives list
    • Attendies
    • Agenda
    • Document Library

basicmeeting

  • Blank Meeting:
    • A blank meeting site that can be customized to suite the requirement
  • Decision Making Meeting:
    • This template is suitable when the purpose of the meeting is to reivew doucments, lists and other informations in order to make a decision. The webparts included are
      • Objectives list
      • Attendies
      • Agenda
      • Document Library
      • Tasks List
      • Decision List

decisionmeeting

 

  • Social Meeting:
    • This template comes handy when organizing a team picnic or party.  The web elements included are
      • Attendies list
      • Directions
      • Image Log
      • Thing to bring List
      • Photo Library
  • MultiPage Meeting:
    • This is similar to Decision Making template but it is designed to accomodate complex decision process. This site comes with two webpages by default and it can accomodate upto 10 individual pages. It includes
      • Objective Lists
      • Attendies Lists
      • Agenda

Enterprise

Enterprise templates are normally used as a top-level or high-level sites in an organizations site collection. It facilitated enterprise level activities in the areas of document management, records management and report management

  • Document Center:
    • A Site to centrally manage enterprise level documents. It has several document management features enabled by default like Major / Minor versionaing, Require check out etc. This templates includes the following webparts.
      • Document Library
      • Relevant documents
      • Upcoming tasks
      • Treeview webpart
  • Records Center:
    • This site template is used to centrally manage organizations data and data sources. The webparts included are
      • Records vault
      • Records routing list
      • Information management policy
      • Unassigned Records library

recordscenter

 

  • Site Directory:
    • A site template for listing, categorizing important sites in the organizations site collection. The webparts included are
      • Categorized Sites
      • Top Sites
      • Site Map
  • Report Center:
    • This site template as part of Sharepoint business intelligence solution communicates metrics, goals, statues and business intelligence informations by means of the foll0wing web elements
      • Dashboards
      • KPI indicators
      • Webpages

reportcenter

 

  • Search Center:
    • A site that enables users to seach for information. It includes webparts
      • SearchResults
      • Advanced Search
  • Search Center with tabs:
    • This is similar to search center except it comes with two tabs. One tab to search through information in the sites and the other tab ‘people’ that enables to search through peoples.

Publishing

  • News Site:
    • A site for publising news articles and links to news articles. The default webparts includes
    • Sample news page
    • Archive for storing older news

Hope this is useful.

A post on creating custom templates can be found here

Thanks.

Posted in MOSS 2007 | Tagged: , , , , , , , , , , , , , , , , , | 2 Comments »

Retrieving SharePoint List Data using CAML

Posted by Ramprasad Navaneethakrishnan on February 9, 2009

Lets see how to retrieve data from a SharePoint list and display it in a Web Part.

Scenario:

We have a SharePoint custom list with the name ‘MySPList’ which has the following columns.Title, AssignedTo and Status. We want to get all the data from the list for which AssignedTo has a value of ‘Ramprasad’.

CAML Query:

For the above scenario, the CAML query should look like the following..

<Where><Eq><FieldRef Name=’AssignedTo‘/><Value Type=’Text‘>Ramprasad</Value></Eq></Where>

Note here that in SharePoint list, ‘AssignedTo’ column is of type ‘Single Line of  Text’. The corresponding type in CAML is ‘TEXT’ which is mentioned in the CAML query.

Query Execution:

SPList mylist = web.Lists[“MySPList”];
SPQuery query = new SPQuery();
query.Query = “<Where><Eq><FieldRef Name=’AssignedTo’/><Value Type=’Text’>Ramprasad</Value></Eq></Where>”;
SPListItemCollection items = mylist.GetItems(query);

This statement execute the CAML query and stores the results as SPListItemsCollection object.

Loop through the results:

Now loop though the SPListItemsCollection object and get the needed column data .

foreach (SPListItem item in items)
{
DataRow _row = _table.NewRow();
_row[0]  = SPEncode.HtmlEncode(item[“Title”].ToString());
_row[1] = SPEncode.HtmlEncode(item[“AssignedTo”].ToString());
_row[2] =  SPEncode.HtmlEncode(item[“Status”].ToString());
_table.Rows.Add(_row);
}

Step by Step:

1. Open Visual Studio 2008. File -> New -> Project.

2. Select WebPart project template from Sharepoint project type.

3. Copy paste the following code

using System;
using System.Data;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;

using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;

namespace SharePointListDataRetrival
{
[Guid(“7594e58f-eceb-4fce-84b9-e5ce7424aa67”)]
public class SharePointListDataRetrivalWebPart : System.Web.UI.WebControls.WebParts.WebPart
{
DataSet _listData;
public SharePointListDataRetrivalWebPart()
{
}

protected override void CreateChildControls()
{
base.CreateChildControls();
DataGrid dgSpListData = new DataGrid();
dgSpListData.DataSource = GetListData();
dgSpListData.DataBind();
this.Controls.Add(dgSpListData);
}

private DataSet GetListData()
{
_listData = new DataSet();
DataTable _table = new DataTable();
DataColumn dc = new DataColumn(“Title”);
_table.Columns.Add(dc);
dc = new DataColumn(“AssignedTo”);
_table.Columns.Add(dc);
dc = new DataColumn(“Status”);
_table.Columns.Add(dc);
using (SPWeb web = SPContext.Current.Site.RootWeb)
{

SPList mylist = web.Lists[“MySPList”];
SPQuery query = new SPQuery();
query.Query = “<Where><Eq><FieldRef Name=’AssignedTo’/><Value Type=’Text’>Ramprasad</Value></Eq></Where>”;
SPListItemCollection items = mylist.GetItems(query);
foreach (SPListItem item in items)
{
DataRow _row = _table.NewRow();
_row[0]  = SPEncode.HtmlEncode(item[“Title”].ToString());
_row[1] = SPEncode.HtmlEncode(item[“AssignedTo”].ToString());
_row[2] =  SPEncode.HtmlEncode(item[“Status”].ToString());
_table.Rows.Add(_row);
}
}
_listData.Tables.Add(_table);
return _listData;
}
}
}

4.  Project Properties -> Debug -> Under ‘Start Action’ section,Select ‘Start browser with url’ -> Give the name of your sharepoint site. Eg : http://vm:1002

5. Build the project.

6. Deploy the solution

7. Open SharePoint site. Site Settings -> Edit Page -> Add New WebPart -> Locate your webpart by the name – >Select Ok.

Now, you will be now able to see the SharePoint list data in your webpart.

Let me know your comments. Thanks.

Posted in MOSS 2007 | Tagged: , , , , , , , , , | 32 Comments »

Business Data Catalog in MOSS 2007

Posted by Ramprasad Navaneethakrishnan on September 26, 2008

Overview

As per Microsoft, Business Data Catalog (BDC) is a “new business integration feature available in Microsoft Office Sharepoint Server 2007. It is a shared service and it enables MOSS 2007 to surface business data from back-end server applications without any coding.”

Why BDC?

All the data entered into the Sharepoint system gets stored in the content database of that particular Sharepoint application. So by default, a Sharepoint site will get information from its content database. But it is quite natural for an organization to have information stored in multiple databases by numerous applications throughout the organization. For example, inventory software stores its data in a database that is different from a CRM software storing data in a database. But people will find is extremely useful if provided with a space where they can have every bit of information from each and every department in the organization ranging from the up-to-minute logistics information to the up-to-date sales analysis. The BDC feature of Microsoft Office Sharepoint Server 2007 provides the needed business integration for integrating the line of business (LOB) applications with the Sharepoint.

What is BDC?

Business Data Catalog provides built in support for displaying data from two data sources.

·         Databases

·         Web Services

Microsoft promises a “no coding” approach for integrating LOB applications with Sharepoint. Business Data Catalog provides access to the data sources through a metadata model that provides a consistent and simplified client object model. So it is the metadata authors who describe the API of the business applications in xml. After this, the administrators will associate this metadata with the Sharepoint application after which the LOB data is available in the Sharepoint system.

 


Development Environment

The walkthrough below will guide in developing a simple BDC application in MOSS 2007. The following states the database and MOSS settings used by this walkthrough.

MOSS Settings

·         Microsoft Office Sharepoint Server 2007 Enterprise Edition Installed.

o   Standard Edition of MOSS 2007 does not have BDC feature

·         Created a new web application named “KnowMax-1234” from Central Administration.

·         Use the default Shared Services Provider (SSP) associated with the created web application or create a new SSP for the web application KnowMax-1234.

Database details of LOB application

·         Database Server : TARGETMC-VM\SQLEXPRESS

·         Database Name : Test

·         Table Name : dbo.Product

·         Snapshot of the LOB Database :

 

Walkthrough:  Creating a product BDC from LOB database

Objective

The objective of this walkthrough is, “To access the LOB application’s data through BDC and display it in the Sharepoint site inside the Business Data Lists Webpart.” This Webpart will get the ‘ProductID’ as input from the user and gets the corresponding product details from the LOB database. The following is the snapshot of the output.

 

 

 

The “ProductID” is given as 1. And the product detail for this product id is obtained from the LOB database.

 

Authoring Metadata

Authoring the metadata forms the heart of the development process involved in creating the BDC application. Though there are many tools that promises to simplify this process, most of them are ambiguous or non freewares. Some of those tools are

·         Microsoft Business Data Catalog definition editor

o   Gets shipped with the Sharepoint 2007 SDK which is available free for download

·         Metaman

o   Metaman is supposedly good but it comes with a cost as Metaman is not a freeware

 

So avoiding all those ambiguities, let us start writing the BDC metadata in xml. To start of the process, open a notepad and follow the steps below

1.    Since the metadata is an xml file, it starts off with the following lines just like all xml documents

<?xml version=1.0 encoding=utf-8 standalone=yes?>

2.    The LobSystem tag defines the namespaces, the name of the LOB system, the type of the system (Database or Webservice) and the version of the system

<LobSystem xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xsi:schemaLocation=http://schemas.microsoft.com/office/2006/03/BusinessDataCatalog BDCMetadata.xsd Type=Database Version=1.0.0.0 Name=ProductBDC1

xmlns=http://schemas.microsoft.com/office/2006/03/BusinessDataCatalog>

3.    Then create a new instance for this Lob system using the following lines

<LobSystemInstances>

<LobSystemInstance Name=ProductBDC1 >

4.    Define the database, connection and authentication properties of the Lob system using the properties tag.

<Properties>

        <Property Name=rdbconnection Data Source Type=System.String>TARGETMC-VM\SQLEXPRESS</Property>

        <Property Name=rdbconnection Initial Catalog Type=System.String>Test</Property>

        <Property Name=rdbconnection Integrated Security Type=System.String>SSPI</Property>

        <Property Name=DatabaseAccessProvider Type=Microsoft.Office.Server.ApplicationRegistry.SystemSpecific.Db.DbAccessProvider>SqlServer</Property>

        <Property Name=AuthenticationMode Type=Microsoft.Office.Server.ApplicationRegistry.SystemSpecific.Db.DbAuthenticationMode>PassThrough</Property>

        <Property Name=RdbConnection Pooling Type=System.String>false</Property>

      </Properties>

    </LobSystemInstance>

</LobSystemInstances>

5.    Now, create an entity and define its properties

  <Entities>

    <Entity EstimatedInstanceCount=100 Name=Product>

      <Properties>

<Property Name=Name Type=System.String>Name</Property>

      </Properties>

      <Identifiers>

   <Identifier Name=ProductID TypeName=System.String /></Identifiers>

These tags define the entity called Product and its two members, Name and ProductID.

6.    There should be a method that gets the details of the entity based on the input parameters.  The following tags define a method called “GetProducts” which has a query that gets the name and productid of the products entity based on the entered productid. Also the input parameter is defined using the parameter tag with Direction attribute as “In”. The output is the product entity having two members namely name and productid which is defined in the parameter tags with the Direction attribute as “Return”.

      <Methods>

        <Method Name=GetProducts>

          <Properties>

            <Property Name=RdbCommandText Type=System.String>

              SELECT ProductID, Name FROM Product WHERE ProductID = @ProductID

           </Property>

            <Property Name=RdbCommandType Type=System.Data.CommandType>Text</Property>

          </Properties>

          <FilterDescriptors>

            <FilterDescriptor Type=Comparison Name=ProductID>

              <Properties>

                <Property Name=Comparator Type=System.String>Equals</Property>

              </Properties>

            </FilterDescriptor>

          </FilterDescriptors>

          <Parameters>

            <Parameter Direction=In Name=@ProductID>

              <TypeDescriptor TypeName=System.String IdentifierName=ProductID AssociatedFilter=ProductID Name=ProductID>

                <DefaultValues>

                  <DefaultValue MethodInstanceName=ProductFinderInstance Type=System.String > 1 </DefaultValue>

                </DefaultValues>

              </TypeDescriptor>

            </Parameter>

            <Parameter Direction=Return Name=Products>

              <TypeDescriptor TypeName=System.Data.IDataReader, System.Data, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

IsCollection=true Name=ProductDataReader>

              <TypeDescriptors>

                <TypeDescriptor TypeName=System.Data.IDataRecord, System.Data, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

                                Name=ProductDataRecord>

                  <TypeDescriptors>

                    <TypeDescriptor TypeName=System.String IdentifierName=ProductID Name=ProductID>

                      <LocalizedDisplayNames>

                        <LocalizedDisplayName LCID=1033>ProductID</LocalizedDisplayName>

                      </LocalizedDisplayNames>

                    </TypeDescriptor>

                    <TypeDescriptor TypeName=System.String Name=Name>

                      <LocalizedDisplayNames>

                        <LocalizedDisplayName LCID=1033>Name</LocalizedDisplayName>

                      </LocalizedDisplayNames>

                      <Properties>

                        <Property Name=DisplayByDefault Type=System.Boolean>true</Property>

                      </Properties>

                    </TypeDescriptor>

                  </TypeDescriptors>

                </TypeDescriptor>

              </TypeDescriptors>

              </TypeDescriptor>

            </Parameter>

 </Parameters>

7.    Then create an instance for the “GetProducts” method like this.

<MethodInstances>

            <MethodInstance Name=ProductFinderInstance Type=Finder ReturnParameterName=Products />

          </MethodInstances>

 

The complete metadata definition xml is as follows. Copy it into a notepad and save as “ProductBDC.xml”.

<?xml version=1.0 encoding=utf-8 standalone=yes?>

<LobSystem xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xsi:schemaLocation=http://schemas.microsoft.com/office/2006/03/BusinessDataCatalog BDCMetadata.xsd Type=Database Version=1.0.0.0 Name=ProductBDC1 xmlns=http://schemas.microsoft.com/office/2006/03/BusinessDataCatalog>

  <LobSystemInstances>

    <LobSystemInstance Name=ProductBDC1 >

      <Properties>

        <Property Name=rdbconnection Data Source Type=System.String>TARGETMC-VM\SQLEXPRESS</Property>

        <Property Name=rdbconnection Initial Catalog Type=System.String>Test</Property>

        <Property Name=rdbconnection Integrated Security Type=System.String>SSPI</Property>

        <Property Name=DatabaseAccessProvider Type=Microsoft.Office.Server.ApplicationRegistry.SystemSpecific.Db.DbAccessProvider>SqlServer</Property>

        <Property Name=AuthenticationMode Type=Microsoft.Office.Server.ApplicationRegistry.SystemSpecific.Db.DbAuthenticationMode>PassThrough</Property>

        <Property Name=RdbConnection Pooling Type=System.String>false</Property>

      </Properties>

    </LobSystemInstance>

  </LobSystemInstances>

  <Entities>

    <Entity EstimatedInstanceCount=100 Name=Product>

      <Properties>

        <Property Name=Name Type=System.String>Name</Property>

      </Properties>

      <Identifiers>

        <Identifier Name=ProductID TypeName=System.String />

      </Identifiers>

      <Methods>

        <Method Name=GetProducts>

          <Properties>

            <Property Name=RdbCommandText Type=System.String>

              SELECT ProductID, Name FROM Product WHERE ProductID = @ProductID

            </Property>

            <Property Name=RdbCommandType Type=System.Data.CommandType>Text</Property>

          </Properties>

          <FilterDescriptors>

            <FilterDescriptor Type=Comparison Name=ProductID>

              <Properties>

                <Property Name=Comparator Type=System.String>Equals</Property>

              </Properties>

            </FilterDescriptor>

          </FilterDescriptors>

          <Parameters>

            <Parameter Direction=In Name=@ProductID>

              <TypeDescriptor TypeName=System.String IdentifierName=ProductID AssociatedFilter=ProductID Name=ProductID>

                <DefaultValues>

                  <DefaultValue MethodInstanceName=ProductFinderInstance Type=System.String > 1 </DefaultValue>

                </DefaultValues>

              </TypeDescriptor>

            </Parameter>

            <Parameter Direction=Return Name=Products>

              <TypeDescriptor TypeName=System.Data.IDataReader, System.Data, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

                              IsCollection=true Name=ProductDataReader>

              <TypeDescriptors>

                <TypeDescriptor TypeName=System.Data.IDataRecord, System.Data, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

                                Name=ProductDataRecord>

                  <TypeDescriptors>

                    <TypeDescriptor TypeName=System.String IdentifierName=ProductID Name=ProductID>

                      <LocalizedDisplayNames>

                        <LocalizedDisplayName LCID=1033>ProductID</LocalizedDisplayName>

                      </LocalizedDisplayNames>

                    </TypeDescriptor>

                    <TypeDescriptor TypeName=System.String Name=Name>

                      <LocalizedDisplayNames>

                        <LocalizedDisplayName LCID=1033>Name</LocalizedDisplayName>

                      </LocalizedDisplayNames>

                      <Properties>

                        <Property Name=DisplayByDefault Type=System.Boolean>true</Property>

                      </Properties>

                    </TypeDescriptor>

                  </TypeDescriptors>

                </TypeDescriptor>

              </TypeDescriptors>

              </TypeDescriptor>

            </Parameter>

          </Parameters>

          <MethodInstances>

            <MethodInstance Name=ProductFinderInstance Type=Finder ReturnParameterName=Products />

          </MethodInstances>

        </Method>

      </Methods>

    </Entity>

  </Entities>

</LobSystem>

 

After authoring the metadata for the Lob system, we have to just associate this with a web application to make use the BDC.

 

1.    Go to the central administration and select your SSP.

2.    Under Business Data Catalog, click Import application definition

 

 

3.      Choose your metadata file and click “Import”

 

 

 

4.       A warning message will come. Click “Ok” as of now.

5.      You can see your imported application by clicking “View Application” under Business Data Catalog for your SSP

 

 

6.      Now, go to your Sharepoint site and click “Edit Page” under Site Actions

7.      Click “Add a Web Part”

8.      Select the “Business Data List” Web Part under Business Data and click Add

 

 

 

9.      In the newly added Business Data List Web Part click Edit and select Modify Shared Web Part

 

  10.  In the type textbox, click Browse

 

 

 

 

 

 

 

 

 

11.  In the Business Data Type Picker dialog box, select your BDC file and click Ok.

 

 

12.  Click Ok in the business data list properties window (screen shot in step 10.)

13.  Now the Webpart will look like the following.

 

 

 

 

14.  Enter 1 in the productid textbox and click “Retrieve Data”.

15.  The product name associated with the product id in the LOB database gets retrieved like the following.

 

 

Posted in MOSS 2007 | Tagged: , , , , , , , , , | 5 Comments »