Showing posts with label MOSS Customization. Show all posts
Showing posts with label MOSS Customization. Show all posts

Tuesday, May 12, 2009

Smartpart in SharePoint (MOSS) 2007 - Easy Web User Controls

The SmartPart is a generic webpart that can contain an ASP.NET user control. Nothing new you would say, but the SmartPart can give your user control access to the SharePoint object model.

Smart Part allows developers to code simple (or complex) Web User Controls (.ascx files) utilizing the full set of visual development tools in VS and then deploy the result to a SharePoint (MOSS) 2007 site by just configuring the url of the user controls.

Need for SmartPart and it's benefits

  • The SmartPart is a SharePoint Webpart that can host any ASP.NET user control. Creation webparts by using the VS.NET designer(user control) instead of coding everything by hand.
  • It complies with sharepoint object model since it's a type of web part.
  • Easy to deploy user controls in MOSS sites
  • Simple configuration
  • Supports AJAX and hence we can create AJAX enabled Smartpart eaily.

The following steps shows the steps to create and deploy the smartpart in MOSS site

Step 1: Create a SmartPart
TO create a smartpart, we need to create a library project using visual studio editor and add the following code. Add the reference to Microsoft.SharePoint.dll.

using System;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.WebPartPages;
namespace SmartpartSample
{
/// <summay>
/// Description for UserControlContainer.
/// </summay>

[DefaultProperty("Text"),
ToolboxData("<{0}:UserControlContainer runat=server>"),
XmlRoot(Namespace = "SmartpartSample")]
public class SmartpartSample : Microsoft.SharePoint.WebPartPages.WebPart
{
private const string defaultText = "";
private string _userControl = defaultText;
private Control _control = null;

[Browsable(true),
Category("User Control"),
DefaultValue(defaultText),
WebPartStorage(Storage.Personal),
FriendlyName("User Control (.ascx)"),
Description("Path to the User Control (.ascx)")]

public string UserControl
{
// This property has the URL of the user control to be displayed in the web part
get
{
return _userControl;
}
set
{
_userControl = value;
}
}
/// <summay>
/// This method gets the custom tool parts for this Web Part by overriding the
/// GetToolParts method of the WebPart base class. You must implement
/// custom tool parts in a separate class that derives from
/// Microsoft.SharePoint.WebPartPages.ToolPart.

///An array of references to ToolPart objects.
/// </summay>
public override ToolPart[] GetToolParts()
{
// These tool parts are to set the properities of the smart part
ToolPart[] toolparts = new ToolPart[2];
WebPartToolPart wptp = new WebPartToolPart();
CustomPropertyToolPart custom = new CustomPropertyToolPart();
toolparts[0] = custom;
toolparts[1] = wptp;
wptp.Expand(Microsoft.SharePoint.WebPartPages.WebPartToolPart.Categories.Appearance);
custom.Expand("User Control");
return toolparts;
}

/// <summay>
/// Load the UserControl
/// </summay>

protected override void CreateChildControls()
{
base.CreateChildControls();
try
{
if (_userControl != defaultText)
{
_control = this.Page.LoadControl(_userControl);
}
else
{
_control = new LiteralControl(string.Format("To link to content, open the tool pane and then type a URL in the Link text box.", 1, 129, this.ID));
}
}
catch (System.Exception ex)
{
_control = new LiteralControl(string.Format("Error: unable to load {0}
Details: {1}", _userControl, ex.Message));
}
if (_control != null)
{
// Add to the Controls collection to support postback
this.Controls.Add(_control);
}
}

/// <summay>
/// Render this Web Part to the output parameter specified.
/// </summay>

/// The HTML writer to write out to
protected override void RenderWebPart(HtmlTextWriter output)
{
EnsureChildControls();
if (_control != null)
{
_control.RenderControl(output);
}
}
}
}

Step 2: Adding the smart part into MOSS Site
1. Place the dll of the smart part project into the bin folder present in the virtual directory folder of the MOSS site.
2. Add a safe control entry for the smart part in the web.config file of the MOSS Site.

<SafeControl Assembly="Assembly Name of the SmartPart, Version=1.0.0.0, Culture=neutral" Namespace="Namespace of the SmartPart" TypeName="*" Safe="True" />

3. Modify the trust level to WSS_Medium in the web.config as shown below.
<trust level="Full" originUrl="" />

4. Open the SharePoint portal where the web parts have to be deployed.

5. Click on Site Actions->Site Settings->Modify All Site Settings

6. Click on Web parts option under Galleries

7. Click on New tab on the Web Part Gallery page.

8. Click on the checkboxes against the Smart part which we have deployed using the above mentioned steps.

9. Click the “Populate Gallery” button.

Step 3: Placing the User Controls and link to MOSS site

1. Copy the User controls to the UserControls folder in the Virtual directory of the MOSS Site.

2. If the UserControls folder is not available create the same.

Step 4: Using the smart in the site pages

1. Create a new page in the MOSS site and edit the page.

2. Add the Smart Part to the page and edit the properties of the smart part.

3. In the properties window of the smart part provide the user control path to be loaded in that page.

4. The path of the usercontrol file should be in this format “~\UserControls\UserControl File Name”.

5. Click on OK button, now the User control should be visible on the page.

6. Exit the page edit mode.

Tuesday, April 28, 2009

MOSS Introduction for beginners

Microsoft Office SharePoint Server (MOSS) 2007 helps stream-line collaboration, shared business processes, content management, enterprise search, and data sharing. Whether you are working across departments, companies, or great distances, SharePoint Server 2007 lets you share information and work with others with great ease and complete security.

Custom Development needs for MOSS projects

  • .Net framework 3.0/3.5 depends on the user Requirement
  • Windows Server 2003
  • Microsoft Office SharePoint Server
  • Microsoft SQL Server 2005 - used internally by MOSS
  • SharePoint designer

Key Features/Elements of MOSS

  • Enterprise Search
  • Business Intelligence by providing integration with Excel Services, SSRS, PPS etc
  • Enterprise Content Management (ECM)
  • Integration with MS office
  • Security at Site Collection level to list item level
  • Site templates available to create sites and Portals easily
  • Out of the box web parts available having custom functionality by simple configuration
  • Out of the box workflows like approval workflow for implementing custom functionality
  • Integration with Reporting tools like SSRS, BSM, PPS etc
  • Every features is scoped at a Farm, Web application, Site Collection and Web Level
  • Document Management, Policy Management and Auditing
  • Personalization and deployment
  • OOB event handlers at site, web and Item level for custom functionality
  • Site Manager, which replaces the Portal Site Map administration page, is a Web-based drag-and-drop tool for managing a SharePoint site’s navigation, security access, and general look and feel.
  • Office SharePoint Server 2007 includes an LDAP pluggable provider for authenticating users of Office SharePoint Server 2007. This is in addition to the Active Directory provider included with Windows SharePoint Services.
  • Audience Targeting
  • Document collaboration
  • Wikis and Blogs
  • Really Simple Syndication (RSS) support
  • E-mail integration

Friday, April 10, 2009

Creating Custom Web part in MOSS and add custom properties to the Tool part

You can create a Custom web part for implementing the custom functionalites in SharePoint by deriving the class from Microsoft.SharePoint.WebPartPages.webPart Class.

using Microsoft.SharePoint;
using Microsoft.SharePoint.WebPartPages;

public class CustomWebPart : WebPart
{
protected override void CreateChildControls()
{
// to do : Create the child controls of the web part and add to the controls collection
Button btncntrol = new Button();
this.Controls.Add(btncntrol);
}
public override void RenderControl(HtmlTextWriter writer)
{
// render control here
}
}

CreateChildControls and RenderControl methods are used to add controls to the web part also apply styles to the web part.

To add custom properties to the Tool Part in Modified Shared Web Part

[Browsable(true), Category("Behavior"), DefaultValue(false),
WebPartStorage(Storage.Shared),
FriendlyName("Enable values "),
Description("To modify values")]
public bool ShowCustomProperty
{
get
{
return showCustomproperty;
}
set
{
showCustomproperty = value;
}
}

To have more customization in the tool part like “on click of image a dialog should open”. Override GetToolPart method in web part class.

When the end-user chooses to modify a Web Part, the framework will call the GetToolParts method of the Web Part class. By overriding this method, I can control the order and appearance of the Tool Parts.

public override Microsoft.SharePoint.WebPartPages.ToolPart[] GetToolParts()
{
// returns array of tool part. Custom propery is also added here...
}

To learn more about creation of web part and connectable web parts in MOSS Click Here

Export and Import APIs in MOSS for migrating content

To Export Pages / Images/ Webs/Pages from one site or web site or sub site to another SharePoint site using content Migration APIs. This took physical copy of each object (pages, web sites, sub sites, site collection) and it can be moved to any other server.

The Content Migration APIs in Windows SharePoint Services 3.0 provide a flexible set of tools for migrating content between Windows SharePoint Services Web sites. Windows SharePoint Services uses the concept of the content migration package, which can include either single or multiple XML files, and then provides a flexible set of APIs to enable exporting and importing the migration packages. The content import/export feature of the deployment object model allows you to export not only Web site content but also existing dependencies, like security features, user roles, versioning data, workflows, and other metadata.

SPExportSettings settings = new SPExportSettings();
settings.SiteUrl = "http://localhost:2000";
// This is used to specify whether to export all or only incremental changes
settings.ExportMethod = SPExportMethodType.ExportAll;
// Location where the physical files on export are getting stored.
settings.FileLocation = @"c:\export";
settings.FileCompression = false;
settings.CommandLineVerbose = true;

// Settings is assigned to the SPExport object
SPExport export = new SPExport(settings);
// This method exports the content and store as physical files
export.Run();

Similarly, import should also be done in the similar fashion with SPImport class.
These APIs are used to migrate the content(Pages / Images/ Webs/Pages ) with in the same sharepoint server as well as other servers.

SiteUrl - this property defines which site collection the export should use. All objects being exported always have to be in the same site collection. The Content Deployment and Migration API cannot access items in different site collections in a single operation.

ExportMethod - this property allows to define whether to perform an incremental export (value = ExportChanges) or everything (value = ExportAll). Be aware that ExportChanges would require to provide an Export Change Token in a separate property.

FileLocation - this property defines where to store the exported content. The value should point to be an empty directory. If the directory does not exist it will be created during export. If file compression is being used, then only the compressed files will be stored on this location. The uncompressed files will be stored in the directory identified by the value of the system wide TMP environment variable. So you need to ensure that the directory the TMP environment variable points to also needs to have sufficient space available.

FileCompression - this property defines whether the content should be compressed into a CAB file. If you need to archive the exported content or need to transfer it to a different machine you should choose to compress. If you only export the content to import it afterwards using code on the same machine and don't need to archive (e.g. a copy or move operation) then you should decide to disable the compression as this is significantly quicker.

CommandVerbose - this parameter allows to control if the API should provide some verbose output. If you have ever seen the generated output when running STSADM -o export: this is exactly the flag the generates this output. If the value is false no output is generated.

ExcludeDependencies - This property controls whether to export dependent objects like referenced images, master pages or page layouts. If it is unclear if the dependent objects are already in the destination database you should export the dependent objects as well to prevent problems.

IncludeDescendants - This property controls whether to export child objects of the selected objects (like sub webs, lists, list items) or only the selected object. Possible values are None (only the object is exported), Content (List and libraries of a web will be exported but not sub webs) and All (all child content is exported)

Wednesday, April 8, 2009

Customize sharepoint CoreResultsWebPart to apply Audience filtering

The below code is to customize the CoreResultsWebPart (Sharepoint OOB web part) to filter based on audience using Reflection. To do so, we need to derive the web part from CoreResultsWebPart class and override the SetPropertiesOnHiddenObject method.

CoreResultsWebPart class internally uses the hiddenobject class to set all the inputs to generate the Search result result. On overriding the method, we can change the input query.

To learn more about sharepoint search queries and Mananaged property Click here

For Example. to filter based on a key word "Sharepoint", MOSS generates a SQL query like this
SELECT WorkId,Path,Title,Write,Author,HitHighlightedSummary, HitHighlightedProperties,CollapsingStatus FROM Scope() WHERE FREETEXT(defaultproperties, 'SharePoint') ORDER BY Rank Desc

To apply audience, query will become
SELECT WorkId,Path,Title,Write,Author,HitHighlightedSummary, HitHighlightedProperties,CollapsingStatusFROM Scope()WHERE FREETEXT(defaultproperties, 'SharePoint') AND CONTAINS(Audience,'TestAud' ) ORDER BY Rank Desc

Audience property added in the where clause of the query is a managed property which is created using Crawled property. Once added the Audience filter in SQL query, the Search result output is automatically generated based on Audience and key word.

Sample code for audience filtering in MOSS Search Result

using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Microsoft.Office.Server.Search.Query;
using Microsoft.Office.Server.Search.WebControls;
using Microsoft.SharePoint.Administration;
using Microsoft.Office.Server;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Search;
using System.Reflection;

namespace customCoreResultsWebPart
{
public class customCoreResultsWebPart : Microsoft.Office.Server.Search.WebControls.CoreResultsWebPart
{
protected override void SetPropertiesOnHiddenObject()
{
base.SetPropertiesOnHiddenObject();
try
{
Type coreResultsWebPartType = this.GetType();

// get the private field containing the searchResultsHiddenObject srho
FieldInfo searchResultsHiddenObjectField = coreResultsWebPartType.BaseType.GetField("srho", BindingFlags.NonPublic BindingFlags.Instance);

// make sure the field exists
if (searchResultsHiddenObjectField != null)
{
// get the actual internal srho object attached to CoreResultsWebPart
object searchResultsHiddenObject = searchResultsHiddenObjectField.GetValue(this);

// get the type of the srho
Type searchResultsHiddenObjecType = searchResultsHiddenObject.GetType();

// get the keyword query property
PropertyInfo keywordQueryProperty = searchResultsHiddenObjecType.GetProperty("KeywordQuery", BindingFlags.Instance BindingFlags.Public);

// read what the user searched for
string keywordQuery = (string)keywordQueryProperty.GetValue(searchResultsHiddenObject, null);

// use this method to get the keywords as a query string to append to the search
// this doesn't seem to be working yet

MethodInfo keywordQueryMethod = searchResultsHiddenObjecType.GetMethod("GetKeywordsAsQuery", BindingFlags.Instance BindingFlags.NonPublic);
string keywordsAsQuery = (string)keywordQueryMethod.Invoke(searchResultsHiddenObject, null);

// set the keywordProperty to null so we can change it to a fullTextQuery
keywordQueryProperty.SetValue(searchResultsHiddenObject, null, null);

// create a new query and set it
string fullTextQueryString = null;

// get the fullTextQuery field i.e. ADVANCED SEARCH
PropertyInfo fullTextQueryProperty = searchResultsHiddenObjecType.GetProperty("FullTextQuery", BindingFlags.Instance BindingFlags.Public);

// This scenario is called when User used AADVANCED SEARCH
if (fullTextQueryProperty.GetValue(searchResultsHiddenObject, null) != null)
{
// This is in the form of SQL Query
fullTextQueryString = fullTextQueryProperty.GetValue(searchResultsHiddenObject, null).ToString();
}
// For normal Search Scenario, The keyword query is translated into SQL Query
else if (!string.IsNullOrEmpty(keywordQuery))
{
// This scenario, the value is just the Keyword... so modify to a SQL Query
fullTextQueryString = "SELECT WorkId,Path,Title,Write,Author,HitHighlightedSummary, HitHighlightedProperties,CollapsingStatus FROM Scope()WHERE FREETEXT(defaultproperties, '" + keywordQuery + "')";
}
// Not a Valid Search and hence Return
else
{
return;
}
// APPLY AUDIENCE FILTERING
fullTextQueryString = fullTextQueryString + " AND CONTAINS (AUDIENCE,'TestAud')";

// SET the SQL Query to the full Text Query - SET THE HIDDEN OBJECT TO NEW VALUE WITH AUDIENCE FILTER
fullTextQueryProperty.SetValue(searchResultsHiddenObject, fullTextQueryString, null);

// this field needs to be set to true to use a full text query
FieldInfo fullTextQuerySetField = searchResultsHiddenObjecType.GetField("_IsFullTextQuerySetFromForm", BindingFlags.NonPublic BindingFlags.Instance);
fullTextQuerySetField.SetValue(searchResultsHiddenObject, true);

// tell the srho that it is not a keyword query any more
FieldInfo isKeywordQueryField = searchResultsHiddenObjecType.GetField("m_bIsKeywordQuery", BindingFlags.NonPublic BindingFlags.Instance);
isKeywordQueryField.SetValue(searchResultsHiddenObject, false);
}
}
catch (Exception exp)
{
// To do: Exception Handling
}
}
}
}

Thursday, March 19, 2009

Showing the page fields/Controls only in edit mode of the SharePoint page

To show the fields only in the Edit mode of the page, add the controls in the following node by editing the page layout of the page.

PublishingWebControls:EditModePanel control is used to show the controls only in the edit mode of the page.

The way we do this is by putting two edit mode panels on the page layout, one configured to render in edit mode, and another configured to render in view mode:

To show in view mode
<
PublishingWebControls:EditModePanel runat=server id="EditModePanelA" PageDisplayMode="Display">
<
SharePointWebControls:FieldValue runat="server" id="ImageFieldValue" FieldName="PublishingPageImage"/>
PublishingWebControls:EditModePanel>

To show in Edit mode only
<
PublishingWebControls:EditModePanel runat=server id="EditModePanelB">
<
SharePointWebControls:FieldValue id="ContactEMailId" FieldName="ContactEMail" runat="server" />
PublishingWebControls:EditModePanel>


The first one will render its contents when people are viewing the page, while the second one will render when people are editing the page

Creating MenuItem in the site Actions menu and adding Security

The application pages and supporting menu items in the Site Actions menu shown so far have been created in a manner so that they are accessible to all users of a site. However, that isn't always desirable. Application pages are often designed to provide information and functionality that should only be accessible to site administrators. The same shows to create a menu item in the Site Actions menu.

This can be installed to sharePoint as a feature as mentioned in the XML below. You can add an attribute named RequireSiteAdministrator and assign it a value of true so that the menu item only displays to those users who are also site administrators.


< CustomAction Id="SiteActionsToolbar" GroupId="SiteActions" Location="Microsoft.SharePoint.StandardMenu" Sequence="1003" Title="Application Page 3" Description="Check out some typical site properties" RequireSiteAdministrator="True" ImageUrl="/_layouts/images/DECISION.GIF">
< UrlAction url="~site/_layouts/CustomApplicationPages/ApplicationPage3.aspx">
< /CustomAction>


After Installing the feature, the SharePoint site looks like








Activating Auditing Programmatically for a Document Library in SharePoint

In the SharePoint (MOSS) object model, SPList objects and SPListItem objects expose an Audit property that makes it possible to configure auditing. The following example shows how to enable auditing in a single document library.

// Open site and Web objects
SPSite siteCollection = new SPSite(http://localhost);
SPWeb site = site.OpenWeb("testweb");

// Open the document library to enable auditing
SPList docLib = site.Lists("documents");

// Turn on auditing flags.
docLib.Audit.AuditFlags = SPAuditMaskType.View
SPAuditMaskType.ChildDelete;
docLib.Audit.Update();


To enable auditing at site collection level
// Open site object
SPSite siteCollection = new SPSite(http://localhost/);
// Enable auditing for the site
siteCollection.Audit.AuditFlags = SPAuditMaskType.All;
siteCollection.Audit.Update();

Tuesday, March 17, 2009

Reading User Profiles from SharePoint(MOSS) programatically

User profile for SharePoint can be imported from Active directory(using master connection from current domain) and SQL server using Business data catalog(BDC) using an application definition file. Audiences can be created from the user profile information based on some rules.

To read the user profile information, we need the following namespaces.
using Microsoft.Office.Server.UserProfiles;
using Microsoft.Office.Server;
using Microsoft.SharePoint;

// GET THE current web
SPWeb web = SPContext.Current.Web;
// Get the logged in user
SPUser user = web.CurrentUser;

// Get the user context
ServerContext ctx = ServerContext.GetContext(HttpContext.Current);
// Get the user profile associated with the context
UserProfileManager userprofilemgr = new UserProfileManager(ctx);

// Get the user profile based on logged in User
UserProfile userprofile = userprofilemgr.GetUserProfile(user.LoginName);
// Reading User profile Information such as name, designation etc
string name = userprofile["First Name"];

userprofilemgr.GetUserProfile method in above code fails if the user does not have access to manage Audience. The permission to access the User profile is given by the following steps.
1. Open the SharePoint 3.0 Central Administration
2. Click on the Shared Services Provider (Farm SSP in this build) i.e. SSP linked to the current site.
3. Click on ‘Personalization services permissions’ under ‘User Profiles and My Sites’
4. Select the user ‘NT AUTHORITY\Authenticated Users’ and click on ‘Modify Permissions of Selected Users’
5. Select ‘Manage audiences’ and click on ‘Save’
6. ‘Manage Audiences’ right will be added to ‘NT AUTHORITY\Authenticated Users’

Running SharePoint custom code with elevated/ administrative privileges

Whenever writing a custom code(workflow / web parts / event handlers) for MOSS site, we sometimes require administrative previleges to run the custom code.


using Microsoft.SharePoint;

SPSecurity.RunWithElevatedPrivileges(delegate()
{
// Code to Run with admin privileges
});

This will take care of running the code with Administrative privileges. (Administrative account) even the user does not have access to the site.

To access the document in a SharePoint (MOSS) library programmatically

To access the document in a library, we need to do the following steps
1. First we need to create SPSite object for the site collection (E.g http://localhost)
2. Then we need to create SPWeb object inside the site collection (E.g http://localhost/testweb)
3. Get get the file by passing the relative url of the web (E.g /documents/samplefile.doc)
4. After getting the SPFile object, one can access the properties of the file as well as version.

Sample Code
using Microsoft.SharePoint;

SPSite site = new SPSite(http://localhost);
SPWeb spweb = site.OpenWeb("testweb");
SPFile file = spweb.GetFile("/documents/samplefile.doc");

Console.WriteLine(file.Url + ", " + file.Length);
SPFileVersionCollection versions = file.Versions;
Console.WriteLine(versions.Count);

for (int i = 1; i < versions.Count; i++)
{
SPFileVersion ver = versions[i];
Console.WriteLine(ver.VersionLabel + ", " + ver.Size);
}

Monday, March 16, 2009

Integrating InfoPath with Sharepoint List

Microsoft InfoPath supports multiple views of the same form.Based on business requirements and user roles, different views of the form can be shown to different users. The below steps is to integrate Infopath forms with Sharepoint Server

  • Create the Sharepoint List
  • Create the CAML fragment to serve as the base schema to submit to the webservice
  • Create the form template and add the data connections
  • Identify the GUID used as the ID for the List
  • Add controls to the form template to display the current items in the list
  • Add fields and controls for entering new items to submit to the list
  • Add a connection to the sharepoint Lists webservice and define the parameters for calling UpdateListItems web method
  • Add the event handler code required to submit additions, updates and deletions from the list
  • Test the form and publish to Sharepoint Server To a Form Library or As a site content type

Building Windows SharePoint Services Search Queries

Search in Windows SharePoint Services supports three types of search syntax for building search queries:

· Keyword Query syntax (search terms are passed directly to the Search service)
· SQL syntax (extension of SQL syntax for querying databases)
· URL syntax (search parameters are encoded in URL, and posted directly to the search page)

Keyword Query syntax

You can pass two types of terms in a Windows SharePoint Services Search keyword query:
· Keywords (the actual query words for the search request)
· Property filters (the property constraints for the search request)
e.g Keyword site:http://marketing http://customersupport/

Site and URL are the Managed Properties used in Search.

The filtering Search results based on the web sites and sub sites can be done thru OOB search itself by giving the filter site keyword (Note: site is a Managed property). SharePoint allows searching content based on one or more managed property. If the search keyword is “Test”, we need to append the web site URL along with the search keyword in the OOB Search Web part to get the results Test site: http://servername/US. OOB web part provides this functionality and the site filter is appended along with the Search keyword.

Otherwise, the url is given like this http://servername/SearchCenter/Pages/results.aspx?k=Test.

In the above URL, key word and site are used to filter the results.
Where http://servername/SearchCenter/Pages/results.aspx is the Search results page

Mapping Crawled Properties to Managed Properties
To make a crawled property available for the Search experience—to make it available for Search queries and display it in Advanced Search and search results—you must map it to a managed property. You can map multiple crawled properties to a single managed property or map a single crawled property to multiple managed properties. If a managed property has multiple crawled properties mapped to it, and a document contains values for more than one of the crawled properties, the order in which the properties are mapped and their priority determine the managed property’s value.

Multiple Property Filters in Enterprise Search
Enterprise Search in Microsoft Office SharePoint Server 2007 keyword syntax supports the use of multiple property filters within the same query. You can use either multiple instances of the same property filter or different property filters.
Using the Same Property Filter
In this scenario, the keyword query is based on a union of the property filters. This is equivalent to the OR operator used in SQL search syntax.
For example, if you specify the following property filters for a keyword query, both the http://marketing/and http://customersupport/ sites are included in the search:
site:http://marketing/ site:http://customersupport/

Using Different Property Filters
In this scenario, the keyword query is based on an intersection of the property filters. This is equivalent to the AND operator used in SQL search syntax.

For example, if you specify the following property filters for a keyword query, all content authored by John Smith from the http://marketing site is included in the search:
site:http://marketing/ author:"John Smith"

SQL Syntax Examples
Search in Windows SharePoint Services provides support for constructing complex search queries through the SQL syntax. Some examples of what is available when using SQL syntax for search queries include the following:
· Comparison operators, such as ">", "<", or · Multiple logical operators, such as AND, OR, and NOT.

1. Finds relevant results containing the keyword SharePoint.
SELECT WorkId,Path,Title,Write,Author,HitHighlightedSummary, HitHighlightedProperties,CollapsingStatusFROM Scope()WHERE FREETEXT(defaultproperties, 'SharePoint') ORDER BY Rank Desc

2. Finds relevant results containing at least one of the keywords SharePoint and Search. SELECT WorkId,Path,Title,Write,Author,...FROM Scope()WHERE FREETEXT(defaultproperties, 'SharePoint Search') ORDER BY Rank Desc

3. Finds relevant results containing both the keywords SharePoint and Search.
SELECT WorkId,Path,Title,Write,Author,...FROM Scope()WHERE FREETEXT(defaultproperties, '+SharePoint +Search') ORDER BY Rank Desc

4. Finds relevant results containing the exact phrase SharePoint Search.
SELECT WorkId,Path,Title,Write,Author,...FROM Scope()WHERE FREETEXT(defaultproperties, ' "SharePoint Search" ') ORDER BY Rank Desc

5. Finds relevant results containing both the keywords SharePoint and Search but not the keyword WSS.
SELECT WorkId,Path,Title,Write,Author,...FROM Scope()WHERE FREETEXT(defaultproperties, '+SharePoint +Search -WSS') ORDER BY Rank Desc

6. Finds relevant SharePoint results authored by persons named John.
SELECT WorkId,Path,Title,Write,Author,...FROM Scope()WHERE FREETEXT(defaultproperties, 'SharePoint') AND CONTAINS(Author,' "John" ')ORDER BY Rank Desc

7. Finds relevant SharePoint results modified within the last 30 days. SELECT WorkId,Path,Title,Write,Author,...FROM Scope()WHERE FREETEXT(defaultproperties, 'SharePoint') AND Write<=DATEADD(DAY,30,GETGMTDATE())ORDER BY Rank Desc.

Configuring sharePoint Search step by step is available here

Customizing core results web part is avaialble here

Configuring Audiences in Sharepoint Central administration SSP

· Create audience in Central Admin SSP (Shared service Provider)
· Create Rules based on user account or profile.
· Compile Audience group
Once the audience is compiled, then the profiles are loaded into the audience group and we can have any number of rules.

Pre-Requsities to create Audience
1. A SSP(shared service provider) must be created
2. User must have administrative previleges

Adding Custom user Control in SharePoint Page

User Control can be added to SharePoint master file or it can be embedded in a web part. The steps for attaching a user control in SharePoint are described below.
Step1:
Create a user control (*.ascx) file.
Step2:
Put the ascx in C:\Inetpub\wwwroot\wss\VirtualDirectories\1111\USerControls\
Where USerControls is a custom created folder in virtual directory.
Step3:
Copy the usercontrol dll in GAC
Step4:
Edit the web config file as below

Add the usercontrols folder as safe controls
<
SafeControl src="~/userControls/*" includesubfolders="True" safe="True" allowremotedesigner="True">

Add the user controls dll as safe controls

<
SafeControl assembly="usercontrol, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cb1dc3b73b79f0d0" namespace="usercontrol" typename="*" safe="True">

Monday, September 22, 2008

Creating an ASP.Net Page and embed in SharePoint

Sometimes, we may need to create some custom logic in a page and embed in Sharepoint pages as links.
Steps for Creating an ASP.Net page and bring into SharePoint Site
Step 1: Create an ASP.Net page and write the custom code in code behind. Then build.
Step 2: Copy the *.aspx file in C:\program files\....\12\Templates\Layouts folder
Step 3: Install the dll in GAC. If not works properly, copy the dll in bin folder of virtual directory.
Step 4: Refer the aspx file as http://servername/_layouts/*.aspx
These pages will be available for all the sites in the Server.

Page Not found 404 Error Page Customization in MOSS Site

In some applications, the default 404 should be customized to another valid application page to show meaning information to the user. It's very simple to do with some steps.

The following steps should be followed to customize the 404 error message for MOSS.

1. In the MOSS server, should make a copy of
%system drive%\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\LAYOUTS\1033\sps404.html and call it as 404Page.html
2. Should create a Virtual Directory /Errors in IIS under the MOSS root web application.
3. Should create a redirect aspx page, as /Errors/404redirect.aspx. This may be SharePoint Page or Normal ASP.Net Page. This page has the custom message to be shown to the user.
4. In 404Page.html , make the following change:
STSNavigate(“/Errors/404redirect..aspx?oldUrl=" + requestedUrl)
5. create a Console Application and insert the following code and run it in MOSS server. This code sets the new file not found page in sharepoint site.

System. Uri webApplicationUri = new Uri(http://ServerName/);
SPWebApplication webApplication = SPWebApplication.Lookup(webApplicationUri);
webApplication.FileNotFoundPage = " 404Page.html";
webApplication.Update();


v Note:
By default this is set to null. FileNotFoundPage needs to point to an html file that lives in %systemdrive%\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\LAYOUTS\1033. The file needs to be html only.

Saturday, September 13, 2008

Steps for Writing Custom Page Load Logic in SharePoint

One can create custom logic for the pages in sharepoint to implement specific functionality.
Step 1: Create a class overrides from System.Web.UI.MasterPage
public class MasterPageOverride : MasterPage
{
protected override void OnLoad(EventArgs e)
{
// Add custom code here
}
}
Step 2: Strong name the assembly and place in GAC.
Step 3: Edit the MOSS master file(.master) and edit the master directive

The MOSS layouts which inherits this master file has the custom logic.