Wednesday, December 17, 2008

To display the proper error messages in the SharePoint Site

1. On the Web server, navigate to the site directory:Local Drive:\Inetpub\wwwroot\wss\VirtualDirectories\[directory for site] (for example 84)
2. Open Web.config in Notepad.
3. Search for "CallStack". Change the CallStack status to "true".
4. Search for "CustomErrors". Change the mode to "off".
5. Save and close the file.

Thursday, November 20, 2008

Stock Ticker Web Part in SharePoint 2007 using web service

Requirement: To display our company stock quote details on a SharePoint HomePage

Solution:

Two ways:

1) Create web part to display the stock details in a Table,

i) Using rss feed url

ii) Using Web Service.

The sample code using Web Service is as follows:


StockQuote.StockQuote stkquote = new StockQuote.StockQuote();
string quote = stkquote.GetQuote("MCHP");//MCHP is the symbol for Microchip stock
XmlDocument xmldoc = new XmlDocument();
xmldoc.LoadXml(quote);
XmlNodeList nodelist = xmldoc.GetElementsByTagName("Stock");
XmlNode xmlnode = nodelist[0];
string symbol = "", last = "", date, time, change = "", open, high, low, volume = "", mktcap, prevclose, percentgechange = "", annrange, earns, pe, name;
for (int i = 0; i < xmlnode.ChildNodes.Count; i++)
{
XmlNode node = xmlnode.ChildNodes[i];
if (node.Name == "Symbol")
symbol = node.InnerText;
if (node.Name == "Last")
last = node.InnerText;
if (node.Name == "Volume")
volume = node.InnerText;
if (node.Name == "Change")
change = node.InnerText;
if (node.Name == "PercentageChange")
percentgechange = node.InnerText;
}
tblStockTicker = new Table();
TableRow trStockTicker = new TableRow();
TableCell tcStockQuote = new TableCell();
HyperLink hlStockQuote = new HyperLink();
hlStockQuote.Text = "MCHP Quote";
hlStockQuote.NavigateUrl = "http://quotes.nasdaq.com/asp/SummaryQuote.asp?symbol=MCHP&selected=MCHP";
tcStockQuote.Controls.Add(hlStockQuote);
trStockTicker.Cells.Add(tcStockQuote);
TableCell tcBlank = new TableCell();
tcBlank.Text = " ";
trStockTicker.Cells.Add(tcBlank);
TableCell tcQuoteText = new TableCell();
tcQuoteText.Text = "(NASDAQ Exchange - quotes delayed 15 min)";
trStockTicker.Cells.Add(tcQuoteText);
trStockTicker.Cells.Add(tcBlank);
TableCell tcVolume = new TableCell();
tcVolume.Text = "Volume: " + volume;
trStockTicker.Cells.Add(tcVolume);
trStockTicker.Cells.Add(tcBlank);
TableCell tcLast = new TableCell();
tcLast.Text = last;
trStockTicker.Cells.Add(tcLast);
trStockTicker.Cells.Add(tcBlank);
TableCell tcChange = new TableCell();
tcChange.Text = change;
trStockTicker.Cells.Add(tcChange);
trStockTicker.Cells.Add(tcBlank);
TableCell tcPercentageChange = new TableCell();
tcPercentageChange.Text = percentgechange;
trStockTicker.Cells.Add(tcPercentageChange);
trStockTicker.Cells.Add(tcBlank);
tblStockTicker.Rows.Add(trStockTicker);
this.Controls.Add(tblStockTicker);

(Note: I added a web referrence named "Stock Quote" to refer to the web service, http://www.webservicex.net/stockquote.asmx )


The sample code using RSS Feed is as follows:


XmlTextReader rssReader;
XmlDocument rssDoc;
XmlNode nodeRss = null;
XmlNode nodeChannel = null;
XmlNode nodeItem;
rssReader = new XmlTextReader("http://www.nasdaq.com/aspxcontent/NasdaqRSS.aspx?data=quotes&symbol=MCHP");
rssDoc = new XmlDocument();
// Load the XML content into a XmlDocument
rssDoc.Load(rssReader);
XmlNodeList nodelist = rssDoc.GetElementsByTagName("description");
string description = string.Empty;
for (int i = 0; i < nodelist.Count; i++)
{
description = Convert.ToString(nodelist[i].InnerText).Trim();
}
// Loop for the tag
for (int i = 0; i < rssDoc.ChildNodes.Count; i++)
{
// If it is the rss tag
if (rssDoc.ChildNodes[i].Name == "rss")
{
// tag found
nodeRss = rssDoc.ChildNodes[i];
}
}
// Loop for the tag
for (int i = 0; i < nodeRss.ChildNodes.Count; i++)
{
// If it is the channel tag
if (nodeRss.ChildNodes[i].Name == "channel")
{
// tag found
nodeChannel = nodeRss.ChildNodes[i];
}
}
for (int i = 0; i < nodeChannel.ChildNodes.Count; i++)
{
// If it is the item tag, then it has children tags which we will add as items to the ListView
if (nodeChannel.ChildNodes[i].Name == "item")
{
nodeItem = nodeChannel.ChildNodes[i];
//string cdata = nodeItem.Attributes["CDATA"].Value;
string desc = nodeItem["description"].InnerXml;
string decstext = nodeItem["description"].InnerText;
string[] sep = { "\table" };
string[] str = decstext.Split(sep, StringSplitOptions.None);
string strFinal = str[0].Replace("\r\n ", "");
strFinal = strFinal.Replace("\r\n ", "");
strFinal = strFinal.Replace("MCHP", "MCHP quote");
strFinal = strFinal.Replace("% Change", "");
strFinal = strFinal.Replace("Change", "");
strFinal = strFinal.Replace("Last", "(NASDAQ Exchange - quotes delayed by 15 min) ");
strFinal = strFinal.Replace("#DDDDDD", "");
//strFinal = strFinal.Replace("red", "white");
//string strRemove = strFinal.Substring(strFinal.IndexOf("/table"), strFinal.Length);
//strFinal = strFinal.Remove(strFinal.IndexOf("/table"), strFinal.);
Literal lt = new Literal();
lt.Text = strFinal;
//this.Controls.Add(lt);
Table tb = new Table();
TableRow tr = new TableRow();
TableCell tc = new TableCell();
tc.Controls.Add(lt);
tr.Cells.Add(tc);
tb.Rows.Add(tr);
tb.BackColor = Color.Silver;
tb.ForeColor = Color.White;
this.Controls.Add(tb);
}
}
}
}

(Note: I used NASDAQ RSS Feed (http://www.nasdaq.com/aspxcontent/NasdaqRSS.aspx?data=quotes&symbol=MCHP) to get the Microchip Stock details.


2) Deploy the web part to your Sharepoint Site.

3) Modify the SharePoint HomePage to include the above stock web part.


i) Open SharePoint Designer and open your site form "Open Site".
ii) Checkout your home page and open it.
iii) From the top menu, Select "Task Panes" and selct "Web Parts", which will open the web parts available for the site in the right side window.
iv) Select the Stockticker Web Part from the web parts list and drag and drop in the home page where eber required.
v) Add the following Javascript to refresh the Stock Ticker every 15 minutes.



vi) Check in the file and check your site home page to see the Stock details.

Javascrip in SharePoint

To refer Javascript file in Sharepoint 2007,

1) Go to "1033" folder in Layouts folder( c:\program files\common files\microsoft shared\web server extensions\12\template\Layouts\1033). This is the default folder that Sharepoint 2007 refers for Javascript files.


2) Add your custom javascript file in the folder ( for example, StockTicker.js file to refresh the control, with code as
var intervalID;
intervalID = window.setInterval("refreshStockTicker()",3000);
function refreshStockTicker() {document.execCommand("Refresh");};

3) To refer that javascript file in SharePoint, go to the sharepoint page using SharePoint Designer. And, refer it with the "SharePoint:ScriptLink" and "Name" as Javascript file name like,


if (!StockTicker1.IsClientScriptBlockRegistered("refreshCode"))
{ StockTicker1.RegisterClientScriptBlock("refreshCode", code); }


In above, StockTicker1 is the name of the control to be refreshed for every 3 seconds.

Thursday, November 06, 2008

How To Deploy Web Parts in MOSS 2007

Requirement: Deploy Web Part to SharePoint Site.

Procedure:
  1. Build your Web Part with Strong Name: Create a ClassLibrary Project.
  2. Drag and Drop the CustomWebPart.dll to GAC (C:\Windows\Assembly).
  3. Open the VirtualDirectories Folder (C:\Inetpub\wwwroot\wss\VirtualDirectories) and go to the Root Folder of your site. ( For Example your site is "http://localhost:801/sites/TestSite", then open the folder "801".)
  4. Open web.config file and add an SafeControl entry for your web part like, (Note: PublicKeyToken can be copied from GAC).
  5. Reset IIS
  6. Go to your site and Click on "Site Settings" => "Web parts".
  7. Click on "New" web part and Select your Web part and click on "Populate Gallary".
  8. Now go to your site and click on edit page. Click "Add a Web part". Select your web part under "Miscellaneous" section and click on "Add".
  9. You can see your web part now.
Deploy Web part by building Cab file.
  1. Build your Web Part with Strong Name: Create a ClassLibrary Project.
  2. Drag and Drop the CustomWebPart.dll to GAC (C:\Windows\Assembly).
  3. Add "CustomWepPartCab" cab project to the above solution(File => New => Project => Other Project Types => Setup and Deployment Project => Cab Project => "CustomWepPartCab")
  4. Add "Project Output.." by right click on cab project.
  5. Select "Primary output" and "Content Files".
6. Add a new file "manifest.xml" to the cab project as follows:
Note: Please make sure that file name(manifest.xml) is not changed

"











"

7. Add another file with name "CustomWebPart.dwp", the name given in the maifest.xml file as follows:
"

Custom Webpart
Custom Webpart
CustomWebpart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b6ad7af95de74642 publickeytoken value from GAC
CustomWebpart.CustomWebpart

"

Deploying the Cab file:
  1. Go to command prompt(Start => Run => Cmd)
  2. Change the directory to the location where cab file(CustomWebPart.cab) is build.
  3. Execute the following command
  4. stsadm.exe -o addwppack -filename WebPartCab.CAB -url http://SiteUrltoInstallWebPart -globalinstall -force

Wednesday, November 05, 2008

Limiting Search Scope to Wiki Page Library(Document Library) AND Hiding Scope Drop Down

Hi,

I want to search a single Wiki Page Library(or Document Library) and I want to hide the Scope DropDown in UI.

For this, I found some solutions:

1)Create a Wiki Page Library(or Document Library) and note down the URL for later use.(For ex: "http://idc-dk-is:44510/sites/TestSite/WikiPageLibrary", Don't forget to remove the "/Forms/AllPages.aspx" from the URL).

2)Open SharePoint Designer and Open your master page where youwant to include this search.

3) From the main Menu, select "Task Panes" and Check/Select "Web Parts". It will open "Web Parts" task pane on the right hand side of the designer.

4) From the "Web Part List", Filter by "Search" and drag and drop "Search Box" web part to your master page.

5) Select "Code" view for the master page.
To hide the Scope Drop Down, set the following property:
<DropDownModeEx xmlns="urn:schemas-microsoft-com:SearchBoxEx">HideScopeDD

6) To specify search in the specific document library, you need to set two properties, "AppendToQuery" to false and "AppQueryTerms" to the Document Library Url (from step 1) as follows in the Search Webpart.

In spswc:searchboxex, AppendToQuery="false" AppQueryTerms="site:http://idc-dk-is:44510/sites/TestSite/WikiPageLibrary"


Another Solution:


1) Follow the Step 1 specified above to create Wiki Page Library

2)Create a Search Scope For the Document Library and note down the Scope name(For example: WikiSearch with scope rule ( Type = Web Address and Web Address = Folder,"http://idc-dk-is:44510/sites/TestSite/WikiPageLibrary")

3)Follow the steps from 2 to 5 specified in above solution.

4)To specify search in the specific document library, you need to set two properties, "AppendToQuery" to false and "AppQueryTerms" to "Scope:DocLibrarySearchScopeName" as follows.

In spswc:searchboxex webpart,
AppendToQuery="false" AppQueryTerms
Scope:WikiSearch"

Save the modified Master Page and publish it to see the Search returning results from the Doc Library only.

Happy Searching...
Yasovardhan.

Monday, October 27, 2008

To Change the seperator icon after "My Site" and "My Links" in the top right corner of SharePoint HomePage

Since the existing seperator pipe icon('') immediatly after "My Site" and "My Links" is incorporated in "MySite" feature, it can't be directly pointed/changed to some other image, by using SharePoint Designer. For this we need to create a new feature and use this feature instead of existing feature. Please follow the steps mentioned below for that.

1) Copy the new image to SharePoint "Images" folder (i.e "C:\program files\common files\microsoft shared\web server extensions\12\TEMPLATE\IMAGES")

2) Create a new feature in FEATURES folder:
  • Go to FEATURES folder (i.e. "C:\program files\common files\microsoft shared\web server extensions\12\TEMPLATE\FEATURES").
  • Copy the existing "MySite" feature.(Select "MySite" folder) and paste it there.
  • Name the feature as "NewMySite" by renaming the copied folder.
  • It will contain two xml files namely "Feature.xml" and "
    MySiteFeatureElements.xml".

3) Modify "Feature.xml" file:

  • Open the "Feature.xml" in Visual Studio IDE.
  • Create a GUID and replace the Feature Id in the xml with the new GUID.

(To generate GUID, go to the folder "C:\Program Files\Microsoft Visual Studio 8\Common7\Tools" and click on "guidgen.exe" and copy the GUID generated. If you want to have shortcut for generating GUID in the Visual Studio IDE, open Visual Studio IDE. Click on "Tools", then "External tools". In the Dialog window, add the following.

Title : Create &GUID

Command: C:\Program Files\Microsoft Visual Studio 8\Common7\Tools\guidgen.exe

Initial Directory: C:\Program Files\Microsoft Visual Studio 8\Common7\Tools\

Then, click on "OK". Next time Go to "Tools" and click on "Create GUID" to generate new GUID.

  • Replace the "Farm" with "Web" for "Scope" attribute.
  • Replace "TRUE" with "FALSE" for "Hidden" attribute.
  • Save the "Feature.xml" file.

4) Modify "MySiteFeatureElements.xml" file

  • In the xml file, modify the "Sequence" value from 100 to less value (like 90) for each of the three controls.
  • Create new user controls in CONTROLTEMPLATES folder to be pointed in this xml file.
  • Go to CONTROLTEMPLATES folder i.e. "C:\program files\common files\microsoft shared\web server extensions\12\TEMPLATE\CONTROLTEMPLATES"
  • Copy "MySiteLink.ascx" file and paste it and rename it to "NewMySiteLink.ascx".
  • In "newMySiteLink.ascx" file, comment/remove the two lines and insert an image which points to the new image in _layouts folder like:

*

  • Similary copy "MyLinks.ascx" file and paste it & rename it to "NewMyLinks.ascx".
  • Edit the file and comment/remove line and insert new line for image as above.
  • Save the both files
  • Replace the "ControlSrc" urls with the new ascx files created in the above steps as follows:





  • Save the file.

5) Modify the scope in master page file:

Since the default scope of the SharePoint Delegate controls "GlobalSiteLink1" and "GlobalSiteLink2" is "Farm", we don't want to affect these changes in entire farm level, we need to change it to "Web" scope. For that open SharePoint Designer. Open your default master page and change the scope of "GlobalSiteLink1" and "GlobalSiteLink2" Delegate controls to "Web" level.

Web" runat="server"/>

Web" runat="server"/>

6) Install Feature:

  • Open Command Prompt and change the directory to "C:\program files\common files\microsoft shared\web server extensions\12\BIN".
  • Execute the installfeature command as follows

C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN>stsadm -o installfeature -filename NewMySite\Feature.xml -force

7) Activate the Feature to your Site collection:

  • Execute the activatefeature command as follows.

C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN>stsadm -o activatefeature -filename NewMySite\Feature.xml -url http://idc-dk-is:44510/sites/TestSite

8) Reset IIS

9) Open your web site and check the change in the seperator image.

Tuesday, October 07, 2008

Site Restore Problem


When I try to restore a site collection using "stsadm -o retore" command it is giving the following error.
"Your backup is from a different version of Windows SharePoint Services and cannot be restored to a server running the current version. The backup file should be restored to a server with version '12.0.0.6318' or later."

I figured out that my SharePoint version is '12.0.0.6300' (Go to any SharePoint site in the system.Click on Site Settings. It will display the version number as attached in screen shot") The solution is to upgrade my SharePoint to version 12.0.0.6318. I found the link for downlod in the following url:

http://www.microsoft.com/downloads/details.aspx?FamilyID=256CE3C3-6A42-4953-8E1B-E0BF27FD465B&displaylang=en

Download it and install. Now the site restore should work.

Monday, October 06, 2008

Site Administration problem after restoring backup of another person's site collection

When you create a new site collection and restore site collection created by another person, it will restore and replace the site collection administartors from that site. To replace it with your name, go to SharePoint Central administration and click on Site Collection Administartors in Application Managemnt. type your account name as primary administrator and click ok. Now you can go to the site collection and modify all settings.

Tuesday, September 16, 2008

Site BackUp and Restore using STSADM command

Take backup using stsadm command

stsadm.exe -o backup -url <> -filename "<>" -overwrite

Ex: stsadm.exe -o backup -url http://idc-dk-is:801/sites/SalesLibrary -filename "E:\SP Backup\SalesLibraryBackUp.dat" -overwrite

Restore site using stsadm command

stsadm.exe -o restore -url <> -filename "<>" -overwrite

Ex: stsadm.exe -o restore -url http://idc-lt-i00142:20533/sites/saleslibrary -filename "D:\SP Backup\ SalesLibraryBackUp.dat" -overwrite

Friday, July 04, 2008

How to convert string into currency format in C#

string strAmount = 100000;
double dblAmount = Convert.ToDouble(strAmount );

string strAmountInCurrency = string.Format("{0:$#,#.00}", dblAmount ); //returns $1,00,000.00 as result

Customize Sharepoint Search results to open in a browser

Hi,

When u search in share point, results are displayed and if you try to open any xml file (info path file) in the search results, it will ask to open or save. If we try to open it, it will throw some error. To open that in browser follow the steps mentioned below:

Deployment Steps:

I. Create Search Center Site for NDA(parent site) as sub site:

1) Create a sub site named “NDASearch” under NDA site using Search Center Template

a) Go to NDA site. Select Site Actions => Create => “Sites and Workspaces” under Web Pages.

b) Give Title = “NDA Search” and Url Name as http://NDASitePath/NDASearch (ex. http://mchpweb/legal/nda/NDA/NDASearch ).

c) Select the template “Search Center” in “Enterprise” templates.

d) Leave other sections with default values and Click the button “Create”.

II. Binding Search Center Site to the NDA Site Search:

1. Go to the NDA site and select Site Actions

2. Select Site Settings => Select “Search Settings” under “Site Collection Administration”.

3. For “Search Center and Custom Scopes”, select the radio button, “Use custom scopes. Display richer results using the following Search Center:”

4. Add your search center URL (i.e. complete URL without default.aspx like “ http://mchpweb/legal/nda/NDA/NDASearch” or URL without parent site name like “/legal/NDA/NDASearch.”).

5. Click on “Ok” Button.

III. Modify Search Core Results Web Part

1. Go to the results page of the search center created i.e. http://mchpweb/legal/nda/NDA/NDASearch/Results.aspx. ( Click on search center site created and in the Url replace “default.aspx” with “Results.aspx” and press enter to open the search center results page)

2. Click Site Actions => Edit Page. This opens the page in edit mode.

3. Go to “Search Core Results” web part and click on edit button.

4. In the dropdown shown, click on “Modify Shared Web Part”.

5. It will display “Search Core Results” properties panel in right side of the page.

6. Click on “XSL Editor” button under “Data View Properties” tab. It will open Text Entry – Web Page Dialog with default code.

7. Replace the code there with the code from the Section VIII and click “Save” button.

8. Click on “Ok” button in “Data View Properties” tab. (Make sure that you click “Ok” button after clicking the “Save” button. Otherwise changes won’t affect.)

IV. Adding and managing Search Scopes

1. Go to the NDA Site.

2. Select Site Actions => Site Settings => Click on “Search Scopes” under Site Collection Administration.

3. Click on “New Scope” and create a site level scope with the following details.

a. For “Title”, enter meaningful name for the Search scope, like “Search NDA Site” (as it is a scope for Searching NDA site).

b. For “Target Results Page”, select the radio button “Use the default Search Results Page”.

c. Click on “Ok” button. This will create a scope and display it in “Unused Scopes”.

4. Click on the scope you just created. This will open a new page with two sections “Scope Settings” and “Rules”.

5. Click on “New Rule” under “Rules” section. This will open “Add Scope Rule” page.

6. In “Add Scope Rule” page,

a. For “Scope Rule Type”, select the radio button “Web Address (http://server/site)”.

b. For “Web Address”, select “Folder” radio button and enter the folder URL where search needs to be done like your NDA site address (http://mchpweb/legal/nda).

c. For “Behavior”, select the default behavior radio button i.e. “Include - Any item that matches this rule will be included, unless the item is excluded by another rule.”

d. Click on “Ok” button.

7. Similarly add 4 more search scopes for each document library, by following the above mentioned steps from 3 to 6.

a. “Search NDA” - For searching only in the NDA document library (Give NDA Document Library URL as web address.)

b. “Search Amendment” - For searching only in the Amendment document library (Give Amendment Document Library URL as web address.)

c. “Search COI” - For searching in the COI document library (Give COI Document Library URL as web address.)

d. “Search UBA” - For searching in the UBA document library (Give UBA Document Library URL as web address.)

8. After creating the scopes, scopes will not appear in Search Box dropdown immediately (You can check the scope status – “New scope - Ready after next update (starts in X minutes)”). To make the search scope to be immediately available,

a. Go to Central Administration.

b. Click on the Shared Service Provider which is providing search functionality.

c. Click on “Search Settings” under “Search” section.

d. In “Scopes” section, click on “Start Update Now”. You can see the status changing to “Updating”

e. If you refresh the page, it will again show “Start Update Now”. This means scopes are updated and available for use now.

V. Creating New Display Group for Search scopes

1. Go to NDA Site. Select Site Actions => Site Settings => Click on “Search Scopes” under Site Collection Administration.

2. Click on the button “New Display Group”.

3. Give a name to it in “Title” like “NDASearchDisplayGroup”.

4. In the scopes, select the scopes you want to be displayed and what order they need to be displayed by checking the check boxes against each “Scope Name” and by selecting the number in “Position from Top”. (Default scope is populated automatically by the scope whose “Position from Top” is 1).

5. Click on ok.

(NOTE: To manage the search scopes appearing in the NDA site at top right “Search Box” dropdown, go to Site Actions => Site Settings => Click on “Search Scopes” under Site Collection Administration. Click on the Display Group: “Search Dropdown”).

VI. Modifying Search Box Web Part

1. Go to the results page of search center site created i.e. http://mchpweb/legal/nda/NDA/NDASearch/Results.aspx. ( Click on your search center site and in the Url replace “default.aspx” with “Results.aspx” and press enter to open the results page)

2. Click on Site Actions => Edit Page

3. Go to “Search Box” web part and click on edit button.

4. In the drop down displayed, click on “Modify Shared Web Part”. It will open the “Search Box” properties in the right panel.

5. Expand “Scopes Dropdown” tab and for “Dropdown mode”, select “Show, do not include contextual scopes, and default to‘s’ Url”.

6. Expand “Miscellaneous” tab.

a. Replace URL in “Target search results page URL” with search center results page i. e. http://mchpweb/legal/nda/NDA/NDASearch/Results.aspx.

b. For “Scope display group”, enter display group name created in step V (i.e. NDASearchDisplayGroup).

7. Click on “Ok” button.

8. Click on your search center site, which will open default page i.e. http://mchpweb/legal/nda/NDA/NDASearch/default.aspx. Apply the above mentioned steps from 2 to 7.

VII. Modify the “osssearchresults.aspx” page

1. In production machine where SharePoint is installed, open the folder, “C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS”

2. Make a backup of “osssearchresults.aspx” page. (Make sure to take back up of this file to revert back in future if required).

3. Edit “osssearchresults.aspx” page in Notepad or Visual Studio and add the JavaScript function from Section IX inside “<script language="javascript">” tag at the end.

a. In the JavaScript code added, make sure that your search center url is given correctly in the beginning of urlstring.

4. Save the modifed “osssearchresults.aspx” page.

VIII. Code to be replaced in XSLT Editor of Search Core Results Web Part.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >

<xsl:param name="ResultsBy" />

<xsl:param name="ViewByUrl" />

<xsl:param name="ViewByValue" />

<xsl:param name="IsNoKeyword" />

<xsl:param name="IsFixedQuery" />

<xsl:param name="ShowActionLinks" />

<xsl:param name="MoreResultsText" />

<xsl:param name="MoreResultsLink" />

<xsl:param name="CollapsingStatusLink" />

<xsl:param name="CollapseDuplicatesText" />

<xsl:param name="AlertMeLink" />

<xsl:param name="AlertMeText" />

<xsl:param name="SrchRSSText" />

<xsl:param name="SrchRSSLink" />

<xsl:param name="ShowMessage" />

<xsl:param name="IsThisListScope" />

<xsl:param name="DisplayDiscoveredDefinition" select="True" />

<xsl:template name="dvt_1.noKeyword">

<span class="srch-description">

<xsl:choose>

<xsl:when test="$IsFixedQuery">

Please set the 'Fixed Query' property for the webpart.

xsl:when>

<xsl:otherwise>

Enter one or more words to search for in the search box.

xsl:otherwise>

xsl:choose>

span>

xsl:template>

<xsl:template name="dvt_1.empty">

<div class="srch-sort">

<xsl:if test="$AlertMeLink and $ShowActionLinks">

<span class="srch-alertme" >

<a href ="{$AlertMeLink}" id="CSR_AM1" title="{$AlertMeText}">

<img style="vertical-align: middle;" src="/_layouts/images/bell.gif" alt="" border="0"/>

<xsl:text disable-output-escaping="yes">&nbsp;xsl:text>

<xsl:value-of select="$AlertMeText" />

a>

span>

xsl:if>

<xsl:if test="string-length($SrchRSSLink) > 0 and $ShowActionLinks">

<xsl:if test="$AlertMeLink">

|

xsl:if>

<a type="application/rss+xml" href ="{$SrchRSSLink}" title="{$SrchRSSText}" id="SRCHRSSL">

<img style="vertical-align: middle;" border="0" src="/_layouts/images/rss.gif" alt=""/>

<xsl:text disable-output-escaping="yes">&nbsp;xsl:text>

<xsl:value-of select="$SrchRSSText"/>

a>

xsl:if>

div>

<br/>

<br/>

<span class="srch-description" id="CSR_NO_RESULTS">

No results matching your search were found.

<ol>

<li>Check your spelling. Are the words in your query spelled correctly?li>

<li>Try using synonyms. Maybe what you're looking for uses slightly different words.li>

<li>Make your search more general. Try more general terms in place of specific ones.li>

<li>Try your search in a different scope. Different scopes can have different results.li>

ol>

span>

xsl:template>

<xsl:template name="dvt_1.body">

<div class="srch-results">

<xsl:if test="$ShowActionLinks">

<div class="srch-sort">

<xsl:value-of select="$ResultsBy" />

<xsl:if test="$ViewByUrl">

|

<a href ="{$ViewByUrl}" id="CSR_RV" title="{$ViewByValue}">

<xsl:value-of select="$ViewByValue" />

a>

xsl:if>

<xsl:if test="$AlertMeLink">

|

<span class="srch-alertme" >

<a href ="{$AlertMeLink}" id="CSR_AM2" title="{$AlertMeText}">

<img style="vertical-align: middle;" src="/_layouts/images/bell.gif" alt="" border="0"/>

<xsl:text disable-output-escaping="yes">&nbsp;xsl:text>

<xsl:value-of select="$AlertMeText" />

a>

span>

xsl:if>

<xsl:if test="string-length($SrchRSSLink) > 0">

|

<a type="application/rss+xml" href ="{$SrchRSSLink}" title="{$SrchRSSText}" id="SRCHRSSL">

<img style="vertical-align: middle;" border="0" src="/_layouts/images/rss.gif" alt=""/>

<xsl:text disable-output-escaping="yes">&nbsp;xsl:text>

<xsl:value-of select="$SrchRSSText"/>

a>

xsl:if>

div>

<br />

<br />

xsl:if>

<xsl:apply-templates />

div>

<xsl:call-template name="DisplayMoreResultsAnchor" />

xsl:template>

<xsl:template name="SetURLBasedOnDocType">

<xsl:param name="url" />

<xsl:choose>

<xsl:when test="contains($url, '.xml')">

<xsl:value-of select="concat($url,'?OpenIn=Browser')" />

xsl:when>

<xsl:otherwise>

<xsl:value-of select="$url" />

xsl:otherwise>

xsl:choose>

xsl:template>

<xsl:template match="Result">

<xsl:variable name="id" select="id"/>

<xsl:variable name="url" select="url"/>

<xsl:variable name="finalurl" >

<xsl:call-template name="SetURLBasedOnDocType" >

<xsl:with-param name="url" select="url" />

xsl:call-template>

xsl:variable>

<span class="srch-Icon">

<a href="{$finalurl}" id="{concat('CSR_IMG_',$id)}" title="{$url}">

<img align="absmiddle" src="{imageurl}" border="0" alt="{imageurl/@imageurldescription}" />

a>

span>

<span class="srch-Title">

<a href="{$finalurl}" id="{concat('CSR_',$id)}" title="{$url}">

<xsl:choose>

<xsl:when test="hithighlightedproperties/HHTitle[. != '']">

<xsl:call-template name="HitHighlighting">

<xsl:with-param name="hh" select="hithighlightedproperties/HHTitle" />

xsl:call-template>

xsl:when>

<xsl:otherwise>

<xsl:value-of select="title"/>

xsl:otherwise>

xsl:choose>

a>

<br/>

span>

<xsl:choose>

<xsl:when test="$IsThisListScope = 'True' and contentclass[. = 'STS_ListItem_PictureLibrary'] and picturethumbnailurl[. != '']">

<div style="padding-top: 2px; padding-bottom: 2px;">

<a href="{$finalurl}" id="{concat('CSR_P',$id)}" title="{title}">

<img src="{picturethumbnailurl}" alt="" />

a>

div>

xsl:when>

xsl:choose>

<div class="srch-Description">

<xsl:choose>

<xsl:when test="hithighlightedsummary[. != '']">

<xsl:call-template name="HitHighlighting">

<xsl:with-param name="hh" select="hithighlightedsummary" />

xsl:call-template>

xsl:when>

<xsl:when test="description[. != '']">

<xsl:value-of select="description"/>

xsl:when>

xsl:choose>

div >

<p class="srch-Metadata">

<span class="srch-URL">

<a href="{$finalurl}" id="{concat('CSR_U_',$id)}" title="{$url}" dir="ltr">

<xsl:choose>

<xsl:when test="hithighlightedproperties/HHUrl[. != '']">

<xsl:call-template name="HitHighlighting">

<xsl:with-param name="hh" select="hithighlightedproperties/HHUrl" />

xsl:call-template>

xsl:when>

<xsl:otherwise>

<xsl:value-of select="url"/>

xsl:otherwise>

xsl:choose>

a>

span>

<xsl:call-template name="DisplaySize">

<xsl:with-param name="size" select="size" />

xsl:call-template>

<xsl:call-template name="DisplayString">

<xsl:with-param name="str" select="author" />

xsl:call-template>

<xsl:call-template name="DisplayString">

<xsl:with-param name="str" select="write" />

xsl:call-template>

<xsl:call-template name="DisplayCollapsingStatusLink">

<xsl:with-param name="status" select="collapsingstatus"/>

<xsl:with-param name="urlEncoded" select="urlEncoded"/>

<xsl:with-param name="id" select="concat('CSR_CS_',$id)"/>

xsl:call-template>

p>

xsl:template>

<xsl:template name="HitHighlighting">

<xsl:param name="hh" />

<xsl:apply-templates select="$hh"/>

xsl:template>

<xsl:template match="ddd">

xsl:template>

<xsl:template match="c0">

<b>

<xsl:value-of select="."/>

b>

xsl:template>

<xsl:template match="c1">

<b>

<xsl:value-of select="."/>

b>

xsl:template>

<xsl:template match="c2">

<b>

<xsl:value-of select="."/>

b>

xsl:template>

<xsl:template match="c3">

<b>

<xsl:value-of select="."/>

b>

xsl:template>

<xsl:template match="c4">

<b>

<xsl:value-of select="."/>

b>

xsl:template>

<xsl:template match="c5">

<b>

<xsl:value-of select="."/>

b>

xsl:template>

<xsl:template match="c6">

<b>

<xsl:value-of select="."/>

b>

xsl:template>

<xsl:template match="c7">

<b>

<xsl:value-of select="."/>

b>

xsl:template>

<xsl:template match="c8">

<b>

<xsl:value-of select="."/>

b>

xsl:template>

<xsl:template match="c9">

<b>

<xsl:value-of select="."/>

b>

xsl:template>

<xsl:template name="DisplaySize">

<xsl:param name="size" />

<xsl:if test='string-length($size) > 0'>

<xsl:if test="number($size) > 0">

-

<xsl:choose>

<xsl:when test="round($size div 1024) < 1">

<xsl:value-of select="$size" /> Bytes

xsl:when>

<xsl:when test="round($size div (1024 *1024)) < 1">

<xsl:value-of select="round($size div 1024)" />KB

xsl:when>

<xsl:otherwise>

<xsl:value-of select="round($size div (1024 * 1024))"/>MB

xsl:otherwise>

xsl:choose>

xsl:if>

xsl:if>

xsl:template>

<xsl:template name="DisplayString">

<xsl:param name="str" />

<xsl:if test='string-length($str) > 0'>

-

<xsl:value-of select="$str" />

xsl:if>

xsl:template>

<xsl:template name="DisplayCollapsingStatusLink">

<xsl:param name="status"/>

<xsl:param name="urlEncoded"/>

<xsl:param name="id"/>

<xsl:if test="$CollapsingStatusLink">

<xsl:choose>

<xsl:when test="$status=1">

<br/>

<xsl:variable name="CollapsingStatusHref" select="concat(substring-before($CollapsingStatusLink, '$$COLLAPSE_PARAM$$'), 'duplicates:"', $urlEncoded, '"', substring-after($CollapsingStatusLink, '$$COLLAPSE_PARAM$$'))"/>

<span class="srch-dup">

[<a href="{$CollapsingStatusHref}" id="$id" title="{$CollapseDuplicatesText}">

<xsl:value-of select="$CollapseDuplicatesText"/>

a>]

span>

xsl:when>

xsl:choose>

xsl:if>

xsl:template>

<xsl:template name="DisplayMoreResultsAnchor">

<xsl:if test="$MoreResultsLink">

<a href="{$MoreResultsLink}" id="CSR_MRL">

<xsl:value-of select="$MoreResultsText"/>

a>

xsl:if>

xsl:template>

<xsl:template match="All_Results/DiscoveredDefinitions">

<xsl:variable name="FoundIn" select="DDFoundIn" />

<xsl:variable name="DDSearchTerm" select="DDSearchTerm" />

<xsl:if test="$DisplayDiscoveredDefinition = 'True' and string-length($DDSearchTerm) > 0">

<script language="javascript">

function ToggleDefinitionSelection()

{

var selection = document.getElementById("definitionSelection");

if (selection.style.display == "none")

{

selection.style.display = "inline";

}

else

{

selection.style.display = "none";

}

}

script>

<div>

<a href="#" onclick="ToggleDefinitionSelection(); return false;">

What people are saying about <b>

<xsl:value-of select="$DDSearchTerm"/>

b>

a>

<div id="definitionSelection" class="srch-Description" style="display:none;">

<xsl:for-each select="DDefinitions/DDefinition">

<br/>

<xsl:variable name="DDUrl" select="DDUrl" />

<xsl:value-of select="DDStart"/>

<b>

<xsl:value-of select="DDBold"/>

b>

<xsl:value-of select="DDEnd"/>

<br/>

<xsl:value-of select="$FoundIn"/>

<a href="{$DDUrl}">

<xsl:value-of select="DDTitle"/>

a>

xsl:for-each>

div>

div>

xsl:if>

xsl:template>

<xsl:template match="/">

<xsl:if test="$AlertMeLink">

<input type="hidden" name="P_Query" />

<input type="hidden" name="P_LastNotificationTime" />

xsl:if>

<xsl:choose>

<xsl:when test="$IsNoKeyword = 'True'" >

<xsl:call-template name="dvt_1.noKeyword" />

xsl:when>

<xsl:when test="$ShowMessage = 'True'">

<xsl:call-template name="dvt_1.empty" />

xsl:when>

<xsl:otherwise>

<xsl:call-template name="dvt_1.body"/>

xsl:otherwise>

xsl:choose>

xsl:template>

xsl:stylesheet>


IX. Java Script Code to be added in osssearchresults.aspx page

function getURLParam(strParamName)

{

var strReturn = "";

var strHref = window.location.href;

if ( strHref.indexOf("?") > -1 )

{

var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();

var aQueryString = strQueryString.split("&");

for ( var iParam = 0; iParam <>

{

if (aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 )

{

var aParam = aQueryString[iParam].split("=");

strReturn = aParam[1];

break;

}

}

}

return unescape(strReturn);

}

var urlstring = 'http://mchpweb/legal/NDA/NDASearch' + '/Results.aspx?k=' + getURLParam('k') + '&cs=' + getURLParam('cs') + '&u=' + getURLParam('u');

/* replace url only for NDA */

if(window.location.href.indexOf("NDA") > -1)

{

location.replace(urlstring);

}

/* In the above urlstring, replace beginning URL ('http://mchpweb/legal/NDA/NDASearch') with your search center url */