: +91-265-2775555
 : +1-856-831-0505
 : +44-788-443-25-28
 : +45-4052-3137
Prakash software blogs - software development,custom sharepoint,MOSS 2007,Telerik development,C#.net,sharepoint webparts > Tag Clouds
How to Display LOB data in your SharePoint site using BDC (step-by-step)

Here I show you how to display Line-of-Business application data in to your sharepoint site using BDC Feature of MOSS 2007.

This task divided into two modules:

(1)    Create Business Catalog File(ADF) and import into SSP

(2)    Display data in webparts using entities of Business Data Catalog Applications

Module 1:

First step is creating an Application Definition file from your database. Here I choose Northwind database to create a one. There are different tools available online to create ADF file. Here I use MOSS BDC Design Studio.

Open a studio. In left pane it will ask you to connect to database, click on it. New pop up window open. Fill in appropriate information for database connection.

After successful connection, your screen will looks like below.

Connected Design Studio

Now next step is drag and drop entity Customer from left pane to right.

It will open a new wizard dialog box, click next. Now it will asks you to enter entity name, here I keep it as it is (Customers), click next.  Now select key column of entity, here I select CustomerID, click next. Next step will be selecting a title column for entity, again it is CustomerID, click next.  In this step, if you want to apply any filter for this entity specify here, I choose CompanyName column, click on finish button. And your screen looks like below.

Customer entity

Now we are going to add second entity Orders which is in relation with Customers entity. Follow the same step as above except filter step. In that step select none.

Customers and Orders entity in Design studio

Now we will add association between these two entities, click on edit properties link shown as above under Orders entity.

It will popup new dialog, Go to Association tab, click on Add Association button, it will asks you fill up information for association. Look at image below.

Association between entities

We now need to edit the input parameter settings for the “CustomerID” parameter on the Orders Entity. Set the Identifier Entity Name to the Entity supplying the values and the Identifier Name to the Column that is receiving the key value. Look at below image

Relation column input parameter for child entity

That’s it with design. Now we will generate XML file.

Under Build Menu, there is an option “Build BDC Xml”, click on it. It will generate XML. You can see it under BDC Xml tab in right pane. Now save this xml file at your preferred location, under file menu click on option “Save BDC Xml” to save it.

Now import this file in SSP.

Open a central admin site, go to shared service administration site. Under business data catalog section, there is an option “Import application definition”, click on it. Browse for your xml file which is stored at your preferred location; keep other options as it is. Click on Import button, now it is validating file. After that it asks you to enter instance name; I named it “NorthwindInstance”.  

Now under Business data catalog section in SSP, click on view application, it shows you application instance, click on it. Now we have to set permission for this instance. Click on manage permission under it. Add your user name to the list.

 

Business data catalog application Northwind Instance details

At last we need to give permissions for entities as shown above click on each entity and set permissions same as above.

Now we are done with Module 1.

Module 2:

Open a SharePoint site, where you want to display data, then from site setting click on edit page. Add web parts as shown below

Click add button.  Click on edit tool pane properties for “Business Data List” webpart.  Select type as shown in below figure. For this webpart it is primary entity means Customers. Select it.

Now for “Business Data Related List” webpart click on edit tool pane select type Orders and select Relationships OrderByCustomer same as below image. Click on apply.

Now at last we need to relate these two webparts each other.  Look at below how to do it.

That’s it we are done.

Now retrieve data using filter in parent webpart and select record from parent will populate data in child webpart. Look at image below

 

Moreover, you can use this Application Definition File (ADF) to include records in enterprise search but it is not in scope of blog.

For more info on BDC follow RANDY WILLIAMS’s 8 series blog at http://sharepointmagazine.net/technical/administration/everything-you-need-to-know-about-bdc-part-1-of-8

Special thanks to Paresh Rao for helping me understanding BDC concept.

Sharepoint workflow created from sharepoint designer failed on start when list item added from asp.net code via object model
I recently got stuck with one of the strange trouble with a developer. He reported that if he adds a workflow on a list created from sharepoint designer to run automatically when the item is added on list he can not use his code written in one of his asp.net user control to add item into that list. The issue happens is that workflow ends up with message "Failed on start"
 
First instance i suspected security trouble and tried running entire code with elevated permissions but no luck.
 
After looking at the log sharepoint was logging "The root activity type is invalid".
 
The solution found for this trouble is really simple. Adding following configuration in web.config of our asp.net solution resolved the problem.
 

 <configSections>

    <sectionGroup name="System.Workflow.ComponentModel.WorkflowCompiler" type="System.Workflow.ComponentModel.Compiler.WorkflowCompilerConfigurationSectionGroup, System.Workflow.ComponentModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">

      <section name="authorizedTypes" type="System.Workflow.ComponentModel.Compiler.AuthorizedTypesSectionHandler, System.Workflow.ComponentModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

    </sectionGroup>

  </configSections>

  <System.Workflow.ComponentModel.WorkflowCompiler>

    <authorizedTypes>

      <authorizedType Assembly="System.Workflow.Activities, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Workflow.*" TypeName="*" Authorized="True" />

      <authorizedType Assembly="System.Workflow.ComponentModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Workflow.*" TypeName="*" Authorized="True" />

      <authorizedType Assembly="System.Workflow.Runtime, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Workflow.*" TypeName="*" Authorized="True" />

      <authorizedType Assembly="System.Transactions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" Namespace="System*" TypeName="*" Authorized="True" />

      <authorizedType Assembly="mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" Namespace="System*" TypeName="*" Authorized="True" />

      <authorizedType Assembly="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" Namespace="System*" TypeName="*" Authorized="True" />

      <authorizedType Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" Namespace="Microsoft.SharePoint.Workflow" TypeName="SPWorkflowActivationProperties" Authorized="True" />

      <authorizedType Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" Namespace="Microsoft.SharePoint.Workflow" TypeName="SPWorkflowTaskProperties" Authorized="True" />

      <authorizedType Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" Namespace="Microsoft.SharePoint.Workflow" TypeName="SPWorkflowHistoryEventType" Authorized="True" />

      <authorizedType Assembly="Microsoft.SharePoint.WorkflowActions, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" Namespace="Microsoft.SharePoint.WorkflowActions" TypeName="*" Authorized="True" />

    </authorizedTypes>

  </System.Workflow.ComponentModel.WorkflowCompiler>

 
 
MOSS 2007: Server error: http://go.microsoft.com/fwlink?LinkID=96177

While trying to install WSS 3.0 SP1 (http://technet.microsoft.com/en-us/office/sharepointserver/bb735839.aspx) the installation get stuck at task 9 of 10 of SharePoint Products and Technology Configuration Wizard. When tried to access the server, encountered the following error:

 

Server error: http://go.microsoft.com/fwlink?LinkID=96177

 

When look into the “Event Viewer”, found the following error description:

 

The schema version (3.0.149.0) of the database DATA
DATABASE_NAME on DATABA_SESERVER_NAME is not consistent with the expected database schema version (3.X.X.X) on DATABASE_NAME.  Connections to this database from this server have been blocked to avoid data loss.  Upgrade the web front end or the content database to ensure that these versions match.

 

Resolution:

 

The first thing we did was either remove content database from the web application which are having the error or Detach the database. This doesn’t seem to work. So we run the command

 

stsadm –o upgrade –inplace –url Central_Administration_URL –forceupgrade

 

and we were back in the business J.

Advertising SharePoint Search with browser
One nice feature of SharePoint is that you can enable search for your SharePoint site in browsers like google search. As shown in image below, "PSSPL" is a new search created below "Google (Default). Selecting this will search for the SharePoint Site.
 
SharePoint Search with Browser

Here are the steps of how to enable this search:

  1. Open the SharePoint site in SharePoint Designer and
  2. Create an XML file under "Style Library/XSL Style Sheets/" folder. Give it a proper name. In my case it is "OpenSearch.xml".
  3. Copy the below content and paste into "OpenSearch.xml" created at step 2.

<?xml version="1.0" encoding="UTF-8"?>

<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">

      <ShortName>PSSPL</ShortName>

      <Description>Ranvijay SharePoint Search </Description>

      <Url type="text/html" template="http://intranet:12523/_layouts/OSSSearchResults.aspx?k={searchTerms}"/>

      <SyndicationRight>open</SyndicationRight>

</OpenSearchDescription>

  1. Open master page and add the following entry under "head" tag.

<link title="PSSPL" type="application/opensearchdescription+xml" rel="search" href="/Style%20Library/XSL%20Style%20Sheets/OpenSearch.xml" />

Now, it's time to search the SharePoint content using browser. Open your SharePoint site in the browser. The search button in Internet Explorer 7 will turn orange, indicating it has found a search provider for the current page.

How to add master page with styles and images in site definition

There is often a requirement to add customized master page (with images and css) while creating a site definition. Here I'm going to explain "How to add these items while creating a site definition". 

 

Below image shows the structure of my Visual Studio solution structure

 

 Site Definition Solution Structure

As you can see in the preceding image, under "12->SiteTemplates->NACBAChapterSite" folder there is one master page "Chapter.master" that will be used while creating a site using this template. Supporting images and css files are placed under "styles" and "images" folders.

 

Now, our goal is to put these files in master page gallery when the site is created using this template. To achieve this do the following in "onet.xml" file (see above solution structure image).

 

  1. Add the following entry under "<Project> node

<ListTemplates>

<ListTemplate Name="mplib" DisplayName="$Resources:MasterPageGallery;" Description="$Resources:global_onet_mplib_desc;" SetupPath="global\lists\mplib" Type="116" BaseType="1" Path="GLOBAL" Hidden="TRUE" HiddenList="TRUE" NoCrawl="TRUE" Unique="TRUE" Catalog="TRUE" OnQuickLaunch="FALSE" SecurityBits="11" AllowDeletion="FALSE" AllowEveryoneViewItems="TRUE" Image="/_layouts/images/itdl.gif" AlwaysIncludeContent="TRUE" DocumentTemplate="100" />

</ListTemplates>

  1. Add following entry in the <Project><Configurations><Configuration> node

<Modules>

<Module Name="MasterPage" />

<Module Name="Images" />

<Module Name="Css" />

</Modules> Here first module entry is to locate master page, second one is to locate different images and the third one is used to add css files.

  1. This step actually adds the files to the master page gallery. Add the following entry under "<Project><Modules>" to add chapter.master to the master page gallery

<Module Name="MasterPage" List="116" Url="_catalogs/masterpage" RootWebOnly="FALSE">

<File Url="Chapter.master" Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE" />

</Module> Here "Name=MasterPage" refers to the module entry created in step 2. Similarly to add css add the following entry under "<Project><Modules>"

<Module Name="Css" List="116" Url="_catalogs/masterpage/styles" Path="styles" RootWebOnly="FALSE">

<File Url="color_layout1_blue.css" Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE" />

<File Url="color_layout1_green.css" Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE" />

<File Url="color_layout1_orange.css" Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE" />

<File Url="color_layout1_purple.css" Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE" />

<File Url="color_layout1_red.css" Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE" />

<File Url="template_layout1.css" Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE" />

</Module> Same you need to do for the images.

Once done with the above steps, you need to deploy the solution. You can do this with WSPBuilder or MSBuild. Deployment is not in the scope of this article. For any help you can contact me on ranvijay@prakashinfotech.com

Thank You

Ranvijay Singh
Activate Feature for Specific List [Special Case]
Normally, When one wants to activate a particular feature to specific List in WSS then he will have to create a specific list by feature itself and then would have to register the feature to that List by Registration ID. But Recently, I had a special case while developing our in-house Module MOM. In that, I had already defined my custom List through the Site Settings--> Site Libraries and Lists --> Custom List. But then there was a need for a feature which was only to be applied to this list. The feature was to add an Item [Email Again] to the Edit Control Block of that List. So, To solve this problem we followed steps below:
1. Created a custom content Type for the Site with no columns.
2. Created a Feature for the Edit Control Block Item.
3. Activated the Feature on the custom content type created earlier.
4. Now, From the Web Front End, In the List Settings, allowed the management of Content Type for that specific List.
5. Then, Added custom content Type to the Specific List and made it the default content type and removed the other content type [Item] which was there by default.
6. Customized this content type for this specific List by adding the columns which were defined for the specific List.
7. Now, User can only create an item in that specific List with the new custom content type and the feature is already activated on the custom content type.
Connecting Web parts in sharepoint

This programming task describes how to connect two SharePoint Web Parts: a Web Part that can consume a single value and another Web Part that can provide a single value.

The SharePoint Web Part infrastructure provides a standardized set of interfaces called connection interfaces that allow Web Parts to exchange information with each other at run time.

I will give a simple example of passing single data between two webparts.

Connectable Web Parts in VS.NET

You are ready now to create the two Web parts within a new class library project. One class will be Provider and other will be consumer class. We will have one interface also.

WebPart should be inherited from using Microsoft.SharePoint.WebPartPages.WebPart;

//--------------------------------------------------------------------------
// Code to be inserted in IDataProvider.cs
//--------------------------------------------------------------------------

namespace ConnectingWebPart

{

    public interface IDataProvider

    {

        string ProposalID { get; }

    }

}

//--------------------------------------------------------------------------
// Code to be inserted in Provider.cs
//--------------------------------------------------------------------------

namespace ConnectingWebPart

{

public class Provider : WebPart, IDataProvider

{

                        protected TextBox txtProvider;

                        protected Button btnSend;

protected override void CreateChildControls()

                        {

                                    txtProvider= new TextBox();

                                    btnSend= new Button();

btnSend.Text = "Send data";

                                    Controls.Add(txtProvider);

                          Controls.Add(btnSend);

}

protected override void RenderContents(HtmlTextWriter writer)

            {

                 

                                    txtProvider.RenderControl(writer);

             

                                     btnSend.RenderControl(writer);

 

}

 

[System.Web.UI.WebControls.WebParts.ConnectionProvider("Proposal ID", AllowsMultipleConnections = true)]

                        public IDataProvider GetProposalProvider()

            {

                                                return this;

 }

 

             public string ProposalID

            {

                                                get

            {

                           return txtProvider.Text;               

            }

 }

            }    

}

 

//--------------------------------------------------------------------------
// Code to be inserted in Consumer.cs
//--------------------------------------------------------------------------

namespace ConnectingWebPart

{

    public class Consumer: WebPart

    {

            protected TextBox txtProvider;

private IDataProvider ProposalProvider;

 

[System.Web.UI.WebControls.WebParts.ConnectionConsumer("Proposal ID")]

       public void RegisterCustomerProvider(IDataProvider provider)

       {

           

this.ProposalProvider = provider;

       }

            protected override void CreateChildControls()

            {

                        txtConsumer= new TextBox();

                        Controls.Add(txtConsumer);

 }

            protected override void RenderContents(HtmlTextWriter writer)

{

                        if (this.ProposalProvider != null)

                    txtConsumer.Text = this.ProposalProvider.ProposalID;

txtConsumer.RenderControl(writer);

            }

    }

 

}

Deploying a Web Part assembly in SharePoint

After building a successful web part assembly it’s time to deploy it to  SharePoint site, you can deploy a Web Part assembly to one of two locations:Bin directory & Global assembly cache.

I will deploy the web part assembly in the Global assembly cache.

Here are the steps:

1. Register the assembly using strong key name.

2. Add the DWP files to the project. Every Web Part class should have a corresponding .dwp file. This is an XML file containing some details of the Web Part, such as the title and the description, but more important, a link to the assembly containing the code that needs to be executed.

<?xml version="1.0" encoding="utf-8"?>
<WebPart xmlns="http://schemas.microsoft.com/WebPart/v2" >
      <Title>Provider Webpart</Title>
      <Description></Description>
      <Assembly> ConnectingWebPart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=76367eea108dc205</Assembly>
      <TypeName>ConnectingWebPart.Provider</TypeName>
</WebPart>

Same you can create for consumer web part too.

3. Your project should also contain one manifest.xml. This file is used during the deployment of the Web Part.

...
  <SafeControls>
     <SafeControl
       Namespace="ConnectingWebPart"
       TypeName="*"
     />
...
  <DwpFiles>
    <DwpFile FileName="Provider.dwp"/>
    <DwpFile FileName="Consumer.dwp"/>
  </DwpFiles>

4. Create a CAB file project and include the project output and the content files. Then includes the both the .dwp files through files option. Now build & copy the .CAB file this location “C:\program Files\Common Files\Microsoft Shared\Web Server Extensions\12\bin”.

5. Modify the web.config of your virtual server and elevate the trust-level to WSS-Medium.

<trust level="WSS_Medium" originUrl="" />

6. Use the STSADM.EXE tool to add the Web part package to the virtual server of your choice.

C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN>stsadm -o addwppack -filename ConnectingWebPartCab.CAB -url http://psspl-spserver:789 -globalinstall –force

If you make changes,first delete the package & then add the paakage again.

C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN>stsadm -o deletewppack -name ConnectingWebPartCab.CAB -url http://psspl-spserver:789

IISRESET.

7.Once the webparts are added to your site pages set the connection between the two webparts.

Impersonation in SharePoint 2007

Impersonation is used when the code needs to be executed with permissions greater than that of the current user (like instantiating a site collection or enumerating list permissions or reading a lookup / configuration list on which user may not have access rights).

In such situations, the code needs to be executed with elevated permission level or under the context of user with higher permissions i.e. Impersonation.

There are two methods available:

Method 1

This allows you to use the Microsoft.SharePoint.SPSite constructor to instantiate a site collection object that runs as if that user was making changes.
SPSite site = new SPSite("SiteCollection_Url");
SPWeb web = site.OpenWeb();
SPUser user = web.AllUsers["User_Name"];
SPUserToken token = user.UserToken;
SPSite impersonatedSiteCollection = new SPSite("SiteCollection_Url", token);
 
Any objects (SPWeb, SPList, etc) that you create from this impersonated site collection will execute as the impersonated user.
 
Method 2
 
We can also implement this method by creating dummy delegate method within a code.

SPSecurity.RunWithElevatedPrivileges(delegate()
{

     //code goes here to do our work

});
 
Where to Use -
 
This approach can be used in scenarios to read or update Site Collection, Site related objects using Full control in event handlers, features or web parts (i.e. code being executed under SharePoint Context.
 
Unauthorized Exception 401.1 While Calling Web Service In SharePoint.

Here I am specially discussing about issue related to SharePoint Web Service  and  .NET Framework 3.5 sp1.

 

 

How problem occur?

 

1.       Already .NET framework 2.0, 3.0, WSS and MOSS installed on machine. All site and application works fine as expected. We run four sites of SharePoint on port 80 using hostHeader.

2.       Web service call also works fine.

3.       Few days back .NET Framework 3.5 SP1 installed on machine. Now problem started.

 

Problem is such that when I use my local machine to call web service. It works fine.

                For Example Application on my local machine and SharePoint site is somewhere on live server. In this case I am able to authenticate the request and get proper data. But when I transfer my application to live server and run same application it gives me unauthorized exception 401.1 even though application and web service on same machine.

 

Cause of Problem:

 

1.       Problem is related to host header. If I used other site on same machine with different port (like 5580) then call to web service without fail.

2.       Another problem is related to IIS integrated authentication. As I change authentication to basic authentication web service call works fine.

3.       As I check IIS log this thing started at particular date and on that date .NET Framework 3.5 SP1 get installed on machine.

 

Solution:            

1.       This is very simple solution but for this you have to compromise with security , use basic authentication instead of integrated authentication in IIS.

2.       Please use following knowledge base article from Microsoft.

http://support.microsoft.com/kb/896861

                       search in google by “Unauthorized Exception 401.1 While Calling Web Service In SharePoint.”.

 

Above article suggest two methods to resolve this issue and you need to use one of them. Both use registry so please registry backup before this. I used first one get solution.

 

Method 1: Disable the loopback check

Follow these steps:
Click Start, click Run, type regedit, and then click OK.

1.     In Registry Editor, locate and then click the following registry key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa

2.     Right-click Lsa, point to New, and then click DWORD Value.

3.     Type DisableLoopbackCheck, and then press ENTER.

4.     Right-click DisableLoopbackCheck, and then click Modify.

5.     In the Value data box, type 1, and then click OK.

6.    Quit Registry Editor, and then restart your computer.

Method 2: Specify host names

To specify the host names that are mapped to the loopback address and can connect to Web sites on your computer, follow these steps:

1.     Click Start, click Run, type regedit, and then click OK.

2.     In Registry Editor, locate and then click the following registry key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0

3.     Right-click MSV1_0, point to New, and then click Multi-String Value.

4.     Type BackConnectionHostNames, and then press ENTER.

5.     Right-click BackConnectionHostNames, and then click Modify.

6.     In the Value data box, type the host name or the host names for the sites that are on the local computer, and then click OK.

7.     Quit Registry Editor, and then restart the IISAdmin service.

SharePoint Object Model namespaces & Classes - For Beginners
There are two important namespaces availabe in WSS & MOSS.
 
The Microsoft.Office.Server namespace is the root namespace of all Office Server objects and Microsoft.SharePoint is the root namespace for all WSS objects.
 
The below illustrates some of the key classes contained in each of these namespaces, as well as to which functional area they belong.

Document Libraries (Microsoft.SharePoint)
SPDocumentLibrary , SPPictureLibrary

Business Data Catalog (Microsoft.Office.Server.ApplicationRegistry.Administration)
EntityCollection , ApplicationRegistry

Features (Microsoft.SharePoint)
SPFeatureDefinition, SPFeatureScope, SPElementDefinition, SPFeature, SPFeatureProperty

Sites (Microsoft.SharePoint)
SPSite, SPSiteAdministration, SPSiteCollection, SPWeb

Meetings (Microsoft.SharePoint.Meetings)
SPMeeting, MtgUtility

User Profiles (Microsoft.Office.Server.UserProfiles)
UserProfile, UserProfileManager

Solutions (Microsoft.SharePoint.Administration)
SPsolution, SPFeatureReceiver, SPSolutionCollection

Lists (Microsoft.SharePoint)
SPList, SPListItem, SPListItemCollection

Note:
 
To add a reference to a Sharepoint API, Right-click the project(in VS) and select Add Reference. Click the Browse tab and select the following directory:

C:\program files\common files\microsoft shared\web server extensions\12\isapi
1 - 10 Next