Thursday, October 28, 2010

Search Architecture

Search Architecture in Sharepoint 2007

At the right side of the figure, there are various repositories, also referred to as content sources, that can be accessed and crawled out of the box. In the list, you will find,

1. External Web sites

2. Sharepoint sites

3. Public Microsoft exchange folders

4. Any line of business data you are able to connect via Business Data Catalog

5. Network shares

6. Lotus Notes databases

Protocol handlers open the door to the location of the arbitrary repository for the crawler, and IFilters make it possible to open the rich resources (Such as Office documents) stored within the location and Index their content.

As a result of all of this crawling, an index file is built up and Data is stored in the Search Database. The Index file is the physical file stored in the system.

All of the Metadata collected during the crawling process such as values of the custom columns for the documents in Sharepoint document libraries, is stored in the property store and will help users build more complex search queries.

There are numerous pieces that make up the configuration data. In the case of Sharepoint, all of this data is stored in the Database under the control of shared service provider. This data includes: The configuration data for the Ranking algorithm, the keywords and the best bets that administrators can set, The schema elements used for defining the queries, and other elements, that involved in Indexing and Searching, the scopes for limiting the resource, the logs created during the logging.

There are 2 Search APIs for the Developers. The first one the Search Administration API. It allows developers to programmatically perform the tasks administrators are doing in the Administration site of the Shared Services Provider. The bottom is the Search API. Probably for the most integrating part of the developers. This API is fully managed and consists of a rich object model.

Wednesday, October 27, 2010

Send Mails through Sharepoint 2007.

How to Send Mail from Sharepoint 2007

Mails can be send through a Sharepoint site as mentioned below.

string strTo = “To Address”;

string strFrom = “From Address”;

string strSubject = “Subject”;

StringDictionary headers = new StringDictionary();

headers.Add("to", strTo);

headers.Add("from", strFrom);

headers.Add("subject", strSubject);

headers.Add("content-type", "text/html"); //This is the default type, so isn't neccessary.

SPUtility.SendEmail(SPContext.Current.Web, headers, “Body of the Message”);

Before doing that, we need to set the Outgoing Email Settings in the Central Administration.


We need to give the Credentials in

Attach Event Receivers in Sharepoint 2007

How to Attach an Event Receiver with a List Programmatically

An event receiver can be attached with the list by 2 Ways.

1. By XML

2. By Code

1. By XML:

Any event receiver needs a Feature to Attach that Event Receiver with the List Template.

So the Feature.xml file will be like follows.

xml version="1.0" encoding="utf-8"?>

<Feature Id="GUID"

Title="Sample Title"

Description="Sample Description"

Version="12.0.0.0"

Hidden="FALSE"

Scope="Scope of the Feature"

ImageUrl="Optional URL"

xmlns="http://schemas.microsoft.com/sharepoint/">

<ElementManifests>

<ElementManifest Location="Element.xml">ElementManifest>

ElementManifests>

Feature>

The last tag is the ElementManifests Tag. In the ElementManifests Tag, we will mention the Element file. In the ElementFile only we will Attach the EventReceiver with the List by using the ListTemplateID.

The Element.xml file will be as follows.

xml version="1.0" encoding="utf-8" ?>

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

<Receivers ListTemplateId="101 – ListTemplate ID of the CustomList">

<Receiver>

<Class>Receiver Class Class>

<Assembly>Receiver AssemblyAssembly>

<Name>Name of the Event ReceiverName>

<Type>ItemAddingType>

<SequenceNumber>Any Unique Sequence NumberSequenceNumber>

Receiver>

Receivers>

Elements>

Once the Feature is Activated, then the EventReceiver “ItemAdding” is added with the Custom List. The Receiver Class will be executed when the Item is added in the List.

The EventReceiver Class needs to be inherited from the SPItemEventReceiver Class. Once this is Class is inherited, then the methods can be Overridden.

public override void ItemAdding(SPItemEventProperties properties)

{

}

2. Through Code:

The above mentioned method can be used for SPItemEventReceiver. In the Same Manner, SpWebEventReceiver Class can also be inherited and the Events Related to the Web can be triggered.

public class SearchCenterWebDeletingEventReceiver : SPWebEventReceiver

{

public override void WebDeleting(SPWebEventProperties properties)

{

try

{

}

catch (Exception ex)

{

}

}

}

This EventReceiver class needs to be Attached with the Web while creating the web itself. To accompalish that,

private void AttachWebDeletingEventReceiver(SPWeb web)

{

try

{

SPEventReceiverDefinitionCollection EventReceivers = web.EventReceivers;

SPEventReceiverDefinition EventReceiverDefinition = EventReceivers.Add();

EventReceiverDefinition.Name = EventReceiverName;

EventReceiverDefinition.Assembly = Assembly Name;

EventReceiverDefinition.Class = Class Name;

EventReceiverDefinition.Type = SPEventReceiverType.WebDeleting;

EventReceiverDefinition.SequenceNumber = Any Sequence Number;

EventReceiverDefinition.Update();

}

}

catch (Exception ex)

{

}

}

Provision a Site through Programmatically C#

How to Create a Sharepoint Site Programmatically using C#:

(or) Provisioning a Site using C#:

We can add a Site in a Site Collection by using the Method Add in the Class AllWebs.

For Example, If I want to add the Search Center with a site collection,

using (SPWeb newSite = currentWeb.Site.AllWebs.Add("Search", DisplayName,"Renault Search Center", currentWeb.Language, "SRCHCEN#0", false, false))

{

newSite.Navigation.UseShared = true;

PublishingWeb pWeb = PublishingWeb.GetPublishingWeb(newSite);

pWeb.InheritCurrentNavigation = true;

pWeb.NavigationShowSiblings = false;

pWeb.IncludePagesInNavigation = false;

pWeb.IncludeSubSitesInNavigation = false;

pWeb.Update();

newSite.Update();

}