Tuesday, June 26, 2007

Developing and Using Web User Control in Web Parts in MOSS 2007


1) Open a new ASP.Net Web Site and name it appropriately.



2) Add a Web User Control file and name it appropriately.



3) Design and create controls according to your need in ascx file.



4) Write the code at button click events as per your requirements.



using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class UserEntry : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void btnSubmit_Click(object sender, EventArgs e)
{
string strName = txtFirstName.Text + " " + txtLastName.Text;
string strAddress = txtCity.Text + ", " + ddlState.SelectedItem.Text + ", " + txtCountry.Text;

lblResName.Text = strName;
lblResAddress.Text = strAddress;
}
protected void btnReset_Click(object sender, EventArgs e)
{
txtFirstName.Text = "";
txtLastName.Text = "";
txtCity.Text = "";
ddlState.SelectedIndex = 0;
txtCountry.Text = "";
}
}





5) Copy your both ascx and ascx.cs file in following path:

C:\Inetpub\wwwroot\wss\VirtualDirectories\80\UserControls

If UserControls folder is not present then create it.

6) Now open a new Web Control Library project and name it appropriately. Add reference of Microsoft.SharePoint.dll in your project. It is present at following path:

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\ISAPI\Microsoft.SharePoint.dll



7) Open a Web Custom Control and name it properly.



8) Inherit Web Part class from System.Web.UI.WebControls.WebParts.WebPart.
Override the CreateChildControls method to load the previously created ascx Web Control.



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

namespace UserControl
{
[DefaultProperty("Text")]
[ToolboxData("<{0}:SPUserControlWP runat=server></{0}:SPUserControlWP>")]
public class SPUserControlWP : WebPart
{
private Control _control;

protected override void CreateChildControls()
{
_control = this.Page.LoadControl(@"~/usercontrols/UserEntry.ascx");
this.Controls.Add(_control);
}
}
}



9) Create Strong-Name for project and build it.

10) Write following codes in your site web.config (i.e. C:\Inetpub\wwwroot\wss\VirtualDirectories\80\web.config) file.



<SafeControls>
<SafeControl Assembly="UserControl, Version=1.0.2721.26545,
Culture=neutral, PublicKeyToken=1af8fa800ec59b02"
Namespace="UserControl" TypeName="*" Safe="True" />
</SafeControls>




<assemblies>
<add assembly="UserControl, Version=1.0.2721.26545,
Culture=neutral, PublicKeyToken=1af8fa800ec59b02" />
</assemblies>



Note: For details regarding way to create strong name and copy version and PublicTokenKey, refer my earlier post.

11) Create webpart file for Web Part.



<webParts>
<webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
<metaData>
<type name="UserControl.SPUserControlWP" />
<importErrorMessage>
Cannot import this Web Part.
</importErrorMessage>
</metaData>
<data>
<properties>
<property name="Title" type="string">
UserControl Web Part
</property>
<property name="Description" type="string">
A
demonstration using UserControl in a SharePoint
WebPart
</property>
</properties>
</data>
</webPart>
</webParts>



12) Add the above created *.webpart xml file to your site.


Note: For details regarding the way to add Web Part, please refer my earlier post --- Developing Custom Web Part.


Suggested Link:

1) WebParticles: Developing and Using Web User Controls as WebParts in Microsoft Office SharePoint Server 2007
http://www.codeproject.com/spoint/WebParticles.asp

Automatic dll registration in GAC


1) Create a Strong-Name for your project. Following steps describes the way to create a Strong-Name:
a. Open the your project properties


b. Go to Signing section in your page, select new in dropdown. “Create Strong Name Key” dialog box gets opened. Enter your strong name and uncheck the check box (as shown in figure below).



2) Now go to Build Events section of property page. Click the Edit Post-build button and enter following command in it:

"C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil.exe" /i $(TargetFileName)

Note: The above path may vary, depending up on the path where you installed your VSTS.


3) Now if you build your project, your project’s dll will be automatically registered in the Global Assembly Cache (GAC).

Thursday, June 7, 2007

Change the search results display in SharePoint Server

1) Navigate to following path
Home => Search page => Site Actions => Edit Page => Search Core Results Web Part => Edit => Modify Shared Web Part => XSL Editor button => Text Entry -- Web Page Dialog

a) Replace all code with:










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



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



<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>



<xsl:template match="/">



<xmp>



<xsl:copy-of select="*"/>



</xmp>



</xsl:template>



</xsl:stylesheet>














b) Press Save
c) Click OK
d) Publish page

2) Now view the Search Core Results web part, it displays some xml. Copy that xml in a file and save it as results.xml for future use.






<All_Results>



<Result>



<id>1</id>



<workid>330</workid>



<rank>867</rank>



<title>Converting Office Word and Office Excel Forms to Office InfoPath.doc</title>



<author>Avinash A</author>



<size>358400</size>



<url>http://ServerName/personal/avinash_a/Shared Documents/Converting Office Word and Office Excel Forms to Office InfoPath.doc</url>



<urlEncoded>http%3A%2F%2FServerName%2Fpersonal%2Favinash%5Fa%2FShared%20Documents%2FConverting%20Office%20Word%20and%20Office%20Excel%20Forms%20to%20Office%20InfoPath%2Edoc</urlEncoded>



<description></description>



<write>5/31/2007</write>



<sitename>http://ServerName/personal/avinash_a</sitename>



<collapsingstatus>0</collapsingstatus>



<hithighlightedsummary>



Converting <c0>Office</c0> Word and <c0>Office</c0> Excel Forms to <c0>Office</c0> InfoPath



<ddd /> Converting <c0>Office</c0> Word and <c0>Office</c0> Excel Forms to <c0>Office</c0> InfoPath



<ddd /> Ways to convert an <c0>Office</c0> Word to <c0>Office</c0> Infopath-



</hithighlightedsummary>



<hithighlightedproperties>



<HHTitle>



Converting <c0>Office</c0> Word and <c0>Office</c0> Excel Forms to <c0>Office</c0> InfoPath.doc



</HHTitle>



<HHUrl>



http://ServerName/personal/avinash_a/Shared Documents/Converting <c0>Office</c0> Word and <c0>Office</c0> Excel Forms to <c0>Office</c0> InfoPath.doc



</HHUrl>



</hithighlightedproperties>



<contentclass>STS_ListItem_DocumentLibrary</contentclass>



<isdocument>1</isdocument>



<picturethumbnailurl></picturethumbnailurl>



<imageurl imageurldescription="Result of type: document">/_layouts/images/icdoc.gif</imageurl>



</Result>



<Result>



<id>2</id>



<workid>32</workid>



<rank>834</rank>



<title>Home</title>



<author>ServerName\Administrator</author>



<size>0</size>



<url>http://ServerName</url>



<urlEncoded>http%3A%2F%2FServerName</urlEncoded>



<description></description>



<write>6/2/2007</write>



<sitename>http://ServerName</sitename>



<collapsingstatus>0</collapsingstatus>



<hithighlightedsummary>



Welcome to Microsoft® <c0>Office</c0> SharePoint® Server 2007 <ddd /> Get started with the new version of Microsoft <c0>Office</c0> SharePoint Server 2007:



</hithighlightedsummary>



<hithighlightedproperties>



<HHTitle>Home</HHTitle>



<HHUrl>http://ServerName</HHUrl>



</hithighlightedproperties>



<contentclass>STS_Site</contentclass>



<isdocument>0</isdocument>



<picturethumbnailurl></picturethumbnailurl>



<imageurl imageurldescription="Result of type: document">/_layouts/images/STS_Site16.gif</imageurl>



</Result>



<Result>



<id>3</id>



<workid>61</workid>



<rank>770</rank>



<title>Events</title>



<author>ServerName\Administrator</author>



<size>0</size>



<url>http://ServerName/Lists/Events/calendar.aspx</url>



<urlEncoded>http%3A%2F%2FServerName%2FLists%2FEvents%2Fcalendar%2Easpx</urlEncoded>



<description>Use the Events list to post information about meetings, deadlines, and other events related to this area.</description>



<write>5/30/2007</write>



<sitename>http://ServerName</sitename>



<collapsingstatus>0</collapsingstatus>



<hithighlightedsummary>



New <c0>Office</c0> Server!



</hithighlightedsummary>



<hithighlightedproperties>



<HHTitle>Events</HHTitle>



<HHUrl>http://ServerName/Lists/Events/calendar.aspx</HHUrl>



</hithighlightedproperties>



<contentclass>STS_List_Events</contentclass>



<isdocument>0</isdocument>



<picturethumbnailurl></picturethumbnailurl>



<imageurl imageurldescription="Result of type: document">/_layouts/images/STS_List_Events16.gif</imageurl>



</Result>



<Result>



<id>4</id>



<workid>58</workid>



<rank>745</rank>



<title>Events - All Events</title>



<author>ServerName\Administrator</author>



<size>0</size>



<url>http://ServerName/Lists/Events/AllItems.aspx</url>



<urlEncoded>http%3A%2F%2FServerName%2FLists%2FEvents%2FAllItems%2Easpx</urlEncoded>



<description>Use the Events list to post information about meetings, deadlines, and other events related to this area.</description>



<write>5/30/2007</write>



<sitename>http://ServerName</sitename>



<collapsingstatus>0</collapsingstatus>



<hithighlightedsummary>



New <c0>Office</c0> Server!



</hithighlightedsummary>



<hithighlightedproperties>



<HHTitle>Events - All Events</HHTitle>



<HHUrl>http://ServerName/Lists/Events/AllItems.aspx</HHUrl>



</hithighlightedproperties>



<contentclass>STS_List_Events</contentclass>



<isdocument>0</isdocument>



<picturethumbnailurl></picturethumbnailurl>



<imageurl imageurldescription="Result of type: document">/_layouts/images/STS_List_Events16.gif</imageurl>



</Result>



<Result>



<id>5</id>



<workid>366</workid>



<rank>739</rank>



<title>funding.docx</title>



<author>Chinmay Vartak</author>



<size>18060</size>



<url>http://ServerName/personal/chinmay_vartak/Proposals/funding.docx</url>



<urlEncoded>http%3A%2F%2FServerName%2Fpersonal%2Fchinmay%5Fvartak%2FProposals%2Ffunding%2Edocx</urlEncoded>



<description></description>



<write>5/31/2007</write>



<sitename>http://ServerName/personal/chinmay_vartak</sitename>



<collapsingstatus>0</collapsingstatus>



<hithighlightedsummary>Title funding Name Date </hithighlightedsummary>



<hithighlightedproperties>



<HHTitle>funding.docx</HHTitle>



<HHUrl>http://ServerName/personal/chinmay_vartak/Proposals/funding.docx</HHUrl>



</hithighlightedproperties>



<contentclass>STS_ListItem_DocumentLibrary</contentclass>



<isdocument>1</isdocument>



<picturethumbnailurl></picturethumbnailurl>



<imageurl imageurldescription="Result of type: document">/_layouts/images/icdocx.gif</imageurl>



</Result>



<Result>



<id>6</id>



<workid>368</workid>



<rank>739</rank>



<title>review.docx</title>



<author>Chinmay Vartak</author>



<size>18167</size>



<url>http://ServerName/personal/chinmay_vartak/Proposals/review.docx</url>



<urlEncoded>http%3A%2F%2FServerName%2Fpersonal%2Fchinmay%5Fvartak%2FProposals%2Freview%2Edocx</urlEncoded>



<description></description>



<write>5/31/2007</write>



<sitename>http://ServerName/personal/chinmay_vartak</sitename>



<collapsingstatus>0</collapsingstatus>



<hithighlightedsummary>Title review Name Last Modification Date </hithighlightedsummary>



<hithighlightedproperties>



<HHTitle>review.docx</HHTitle>



<HHUrl>http://ServerName/personal/chinmay_vartak/Proposals/review.docx</HHUrl>



</hithighlightedproperties>



<contentclass>STS_ListItem_DocumentLibrary</contentclass>



<isdocument>1</isdocument>



<picturethumbnailurl></picturethumbnailurl>



<imageurl imageurldescription="Result of type: document">/_layouts/images/icdocx.gif</imageurl>



</Result>



<Result>



<id>7</id>



<workid>436</workid>



<rank>739</rank>



<title>third.docx</title>



<author>Chinmay Vartak</author>



<size>18170</size>



<url>http://ServerName/personal/chinmay_vartak/Proposals/third.docx</url>



<urlEncoded>http%3A%2F%2FServerName%2Fpersonal%2Fchinmay%5Fvartak%2FProposals%2Fthird%2Edocx</urlEncoded>



<description></description>



<write>6/1/2007</write>



<sitename>http://ServerName/personal/chinmay_vartak</sitename>



<collapsingstatus>0</collapsingstatus>



<hithighlightedsummary>Title New review document Name Last Modification Date </hithighlightedsummary>



<hithighlightedproperties>



<HHTitle>third.docx</HHTitle>



<HHUrl>http://ServerName/personal/chinmay_vartak/Proposals/third.docx</HHUrl>



</hithighlightedproperties>



<contentclass>STS_ListItem_DocumentLibrary</contentclass>



<isdocument>1</isdocument>



<picturethumbnailurl></picturethumbnailurl>



<imageurl imageurldescription="Result of type: document">/_layouts/images/icdocx.gif</imageurl>



</Result>



<Result>



<id>8</id>



<workid>123</workid>



<rank>288</rank>



<title>New Office Server!</title>



<author>ServerName\Administrator</author>



<size>0</size>



<url>http://ServerName/Lists/Events/DispForm.aspx?ID=1</url>



<urlEncoded>http%3A%2F%2FServerName%2FLists%2FEvents%2FDispForm%2Easpx%3FID%3D1</urlEncoded>



<description></description>



<write>5/30/2007</write>



<sitename>http://ServerName</sitename>



<collapsingstatus>0</collapsingstatus>



<hithighlightedsummary>



New <c0>Office</c0> Server! <ddd /> New <c0>Office</c0> Server!



</hithighlightedsummary>



<hithighlightedproperties>



<HHTitle>



New <c0>Office</c0> Server!



</HHTitle>



<HHUrl>http://ServerName/Lists/Events/DispForm.aspx?ID=1</HHUrl>



</hithighlightedproperties>



<contentclass>STS_ListItem_Events</contentclass>



<isdocument>0</isdocument>



<picturethumbnailurl></picturethumbnailurl>



<imageurl imageurldescription="Result of type: document">/_layouts/images/STS_ListItem16.gif</imageurl>



</Result>



</All_Results>





















3) Now Open SharePoint Designer and perform following actions:
File Menu => Open Site => Folder Name: "http://ServerName/SearchCenter/Pages/" (folder name will varies)

4) Select the msdnsearchresults.aspx from Folder List on left side of SharePoint designer and double click it to edit page layout.



5) In the newly opened SharePoint designer (i.e. Edit page layout of msdnsearchresults.aspx) open an aspx page.



Open Aspx page => Data View => Select - Managed Data Sources => Add an XML File => Browse to file => Press OK

results.xml file => Show Data => Result => Nodes => Select Title, author, write, imageURL => Drag-n-drop in designer

6) After drag-n-drop of nodes, following sections gets open




<body><form#form1><WebPartPages:DataFormatWebPart>








7) Perform following actions to change the stylesheet:

Column end => click arrow ">" => Common Data View Tasks => Change Layout => Select Layout => Press OK

Results value text => Click ">" => Common xsl:value-of Tasks => Format as: => Picture => Press Yes

Title value text => Click ">" => Common xsl:Value-of Tasks => Format as: => Hyperlink => Press Yes => Hyperlink dialog => Address: => {url} => Text to display: => {title} => Press OK

Write value text => Click ">" => Common xsl:value-of Tasks => Format as: => Date Time => Uncheck ShowTime => Select date format => Press OK

8) Change SharePoint designer in Split mode and Copy following node:
<xsl:stylesheet>... </xsl:stylesheet>






<xsl:stylesheet version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal">



<xsl:output method="html" indent="no"/>



<xsl:decimal-format NaN=""/>



<xsl:param name="FileName" />



<xsl:param name="dvt_apos">'</xsl:param>







<xsl:variable name="dvt_1_automode">0</xsl:variable>



<xsl:template match="/">



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



</xsl:template>



<xsl:template name="dvt_1">



<xsl:variable name="dvt_StyleName">2ColFrm</xsl:variable>



<xsl:variable name="Rows" select="/All_Results/Result" />



<table border="1" width="100%">



<tr>



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



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



</xsl:call-template>



</tr>



</table>



</xsl:template>



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



<xsl:param name="Rows" />



<xsl:for-each select="$Rows">



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



</xsl:for-each>



</xsl:template>



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



<td valign="top" width="50%">



<table border="0" cellspacing="0" width="100%">



<tr>



<td width="25%" class="ms-vb">



<b>Result:</b>



</td>



<td width="75%" class="ms-vb">



<img border="0" src="{imageurl/text()}" />



</td>



</tr>



<tr>



<td width="25%" class="ms-vb">



<b>title:</b>



</td>



<td width="75%" class="ms-vb">



<a href="{url}">



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



</a>



</td>



</tr>



<tr>



<td width="25%" class="ms-vb">



<b>author:</b>



</td>



<td width="75%" class="ms-vb">



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



</td>



</tr>



<tr>



<td width="25%" class="ms-vb">



<b>write:</b>



</td>



<td width="75%" class="ms-vb">



<xsl:value-of select="ddwrt:FormatDateTime(string(write) ,1033 ,'MM/dd/yyyy ')" />



</td>



</tr>



<xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1">



<tr>



<td colspan="99" class="ms-vb">



<span ddwrt:amkeyfield="" ddwrt:amkeyvalue="string($XPath)" ddwrt:ammode="view" />



</td>



</tr>



</xsl:if>



</table>



</td>



<xsl:if test="position() mod 2 = 0" ddwrt:cf_ignore="1">



<xsl:text disable-output-escaping="yes">&lt;/tr></xsl:text>



<xsl:if test="position() != last()" ddwrt:cf_ignore="1">



<xsl:text disable-output-escaping="yes">&lt;tr></xsl:text>



</xsl:if>



</xsl:if>



<xsl:if test="position() = last()" ddwrt:cf_ignore="1">



<xsl:if test="position() mod 2 != 0" ddwrt:cf_ignore="1">



<td>



<xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&amp;nbsp;</xsl:text>



</td>



</xsl:if>



</xsl:if>



</xsl:template>



</xsl:stylesheet>













9) Now go back to Search page and open it in edit mode.
Open Home => Search => Site Actions => Edit Page

Here the Core result Web part does not display edit link, so change the url by removing the query string parameter from the url and type contents=1 in the end of the url.

http://ServerName/SearchCenter/Pages/msdnsearchresults.aspx?contents=1

10) It opens the Web Part Page Maintenance.

Home > Search > Pages > MSDNSearchResults > Web Part Page Maintenance
Web Part Page Maintenance: msdnsearchresults

http://ServerName/SearchCenter/_layouts/spcontnt.aspx?&url=%2fSearchCenter%2fPages%2fmsdnsearchresults.aspx

11) Check the "Search Core Results" and delete it by pressing the delete link present in the toolbar.

Check Search Core Results => Delete => Press OK

12) Click Go Back to Web Part Page => Site Actions => Edit Page => Add a Web Part => Check Search Core Results => Add => Publish => Add a Web Part => Check Search Core Results => Add => Publish

13) Now go back to MSDN tab and type some search keyword.
Home => Search => MSDN tab => type keyword => search

14) Now change the xml:stylesheet.
Site Actions => Edit Page => Search Core Results Web Part => Edit link => Modify Share Web Part => Search Core Results => Xsl Editor button => Replace xml:stylesheet with earlier copied xml:stylesheet.

15) Press OK and Publish the page.

16) Now enter some search keyword in newly created tab and start search. It displays search results according to new xml:stylesheet.



It is also possible to categorize the search results display by changing the xml:stylesheet









<xsl:stylesheet version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal">



<xsl:output method="html" indent="no"/>



<xsl:decimal-format NaN=""/>



<xsl:param name="FileName" />



<xsl:param name="dvt_apos">'</xsl:param>



<xsl:param name="dvt_groupfield" />



<xsl:variable name="dvt_1_automode">0</xsl:variable>







<xsl:template match="/">



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



</xsl:template>



<xsl:template name="dvt_1">



<xsl:variable name="dvt_StyleName">Table</xsl:variable>



<xsl:variable name="Rows" select="/All_Results/Result"/>



<xsl:variable name="dvt_RowCount" select="count($Rows)" />



<table border="0" width="100%" cellpadding="2" cellspacing="0">



<tr valign="top">



<xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1">



<th class="ms-vh" width="1%" nowrap="nowrap"></th>



</xsl:if>



<th class="ms-vh" nowrap="nowrap">id</th>



<th class="ms-vh" nowrap="nowrap">workid</th>



<th class="ms-vh" nowrap="nowrap">rank</th>



<th class="ms-vh" nowrap="nowrap">title</th>



<th class="ms-vh" nowrap="nowrap">author</th>



</tr>



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



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



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



<xsl:with-param name="LastRow" select="$dvt_RowCount" />



</xsl:call-template>



</table>







</xsl:template>



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



<xsl:param name="Rows"/>



<xsl:param name="FirstRow" />



<xsl:param name="LastRow" />



<xsl:variable name="dvt_Rows">



<root>



<xsl:for-each select="$Rows">



<xsl:sort select="author" order="ascending" />



<xsl:if test="(position() &gt;= $FirstRow and position() &lt;= $LastRow)">



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



</xsl:if>



</xsl:for-each>



</root>



</xsl:variable>



<xsl:for-each select="$Rows">



<xsl:sort select="author" order="ascending" />



<xsl:variable name="NewGroup_0">



<xsl:choose>



<xsl:when test="not ($dvt_groupfield)">



<xsl:value-of select="ddwrt:NameChanged(string(author), 0)" />



</xsl:when>



<xsl:otherwise></xsl:otherwise>



</xsl:choose>



</xsl:variable>



<xsl:choose>



<xsl:when test="0" />



<xsl:when test="not($dvt_groupfield) and (not($NewGroup_0='') and position() &gt;= $FirstRow and position() &lt;= $LastRow or ($FirstRow = position()))">



<xsl:variable name="groupheader0">



<xsl:choose>



<xsl:when test="not (author) and (author) != false()">



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



</xsl:when>



<xsl:otherwise>



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



</xsl:otherwise>



</xsl:choose>



</xsl:variable>



<xsl:variable name="groupfooter0">



<xsl:choose>



<xsl:when test="$NewGroup_0=''">



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



</xsl:when>



<xsl:otherwise>



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



</xsl:otherwise>



</xsl:choose>



</xsl:variable>



<xsl:if test="not ((position()=1) or (position()=$FirstRow))">



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



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



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



<xsl:with-param name="fieldvalue" select="$groupfooter0" />



<xsl:with-param name="fieldtype" select="'text'" />



<xsl:with-param name="nodeset" select="msxsl:node-set($dvt_Rows)/root//Result[((author)=$groupfooter0 or ((not(author) or author='') and $groupfooter0=' '))]" />



<xsl:with-param name="groupid" select="'0'" />



<xsl:with-param name="displaystyle" select="'auto'" />



<xsl:with-param name="showfooter" select="true()" />



<xsl:with-param name="showfootercolumn" select="false()" />



</xsl:call-template>



</xsl:if>



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



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



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



<xsl:with-param name="fieldvalue" select="$groupheader0" />



<xsl:with-param name="fieldtype" select="'text'" />



<xsl:with-param name="nodeset" select="msxsl:node-set($dvt_Rows)/root//Result[((author)=$groupheader0 or ((not(author) or author='') and $groupheader0=' '))]" />



<xsl:with-param name="groupid" select="'0'" />



<xsl:with-param name="displaystyle" select="'auto'" />



<xsl:with-param name="imagesrc" select="'/_layouts/images/minus.gif'" />



<xsl:with-param name="alttext" select="'collapse'" />



<xsl:with-param name="altname" select="'expand'" />



<xsl:with-param name="hidedetail" select="false()" />



<xsl:with-param name="showheader" select="true()" />



<xsl:with-param name="showheadercolumn" select="false()" />



</xsl:call-template>



</xsl:when>



</xsl:choose>



<xsl:variable name="BreakOut">



<xsl:choose>



<xsl:when test="not($dvt_groupfield) and position()=$LastRow+1">



<xsl:value-of select="ddwrt:NameChanged('', -1)" />



</xsl:when>



<xsl:otherwise>BreakOut</xsl:otherwise>



</xsl:choose>



</xsl:variable>



<xsl:variable name="dvt_KeepItemsTogether" select="false()" />



<xsl:variable name="dvt_HideGroupDetail" select="false()" />



<xsl:if test="(position() &gt;= $FirstRow and position() &lt;= $LastRow) or $dvt_KeepItemsTogether">



<xsl:if test="not($dvt_HideGroupDetail)" ddwrt:cf_ignore="1">



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



</xsl:if>



</xsl:if>



<xsl:choose>



<xsl:when test="0" />



<xsl:when test="($NewGroup_0 or true()) and not($dvt_groupfield)">



<xsl:variable name="groupfooter0">



<xsl:choose>



<xsl:when test="position() = count($Rows) and ($LastRow &gt;= position() or $dvt_KeepItemsTogether) or not($NewGroup_0) or $NewGroup_0=''">



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



</xsl:when>



<xsl:otherwise>



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



</xsl:otherwise>



</xsl:choose>



</xsl:variable>



<xsl:if test="(position() = count($Rows) and ($LastRow=position() or $dvt_KeepItemsTogether)) or (not($dvt_KeepItemsTogether) and position() &gt; $LastRow and not($BreakOut='BreakOut')) or (not($dvt_KeepItemsTogether) and position() = $LastRow+1) or (position()=last() and $LastRow &gt; last())">



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



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



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



<xsl:with-param name="fieldvalue" select="$groupfooter0" />



<xsl:with-param name="fieldtype" select="'text'" />



<xsl:with-param name="nodeset" select="msxsl:node-set($dvt_Rows)/root//Result[((author)=$groupfooter0 or ((not(author) or author='') and $groupfooter0=' '))]" />



<xsl:with-param name="groupid" select="'0'" />



<xsl:with-param name="displaystyle" select="'auto'" />



<xsl:with-param name="showfooter" select="true()" />



<xsl:with-param name="showfootercolumn" select="false()" />



</xsl:call-template>



</xsl:if>



</xsl:when>



</xsl:choose>



</xsl:for-each>







</xsl:template>



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



<tr>



<xsl:if test="position() mod 2 = 1">



<xsl:attribute name="class">ms-alternating</xsl:attribute>



</xsl:if>



<xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1">



<td class="ms-vb" width="1%" nowrap="nowrap">



<span ddwrt:amkeyfield="" ddwrt:amkeyvalue="string($XPath)" ddwrt:ammode="view"></span>



</td>



</xsl:if>



<td class="ms-vb">



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



</td>



<td class="ms-vb">



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



</td>



<td class="ms-vb">



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



</td>



<td class="ms-vb">



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



</td>



<td class="ms-vb">



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



</td>



</tr>



</xsl:template>



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



<xsl:param name="fieldtitle" />



<xsl:param name="fieldname" />



<xsl:param name="fieldvalue" />



<xsl:param name="fieldtype" />



<xsl:param name="nodeset" />



<xsl:param name="groupid" />



<xsl:param name="displaystyle" />



<xsl:param name="imagesrc" />



<xsl:param name="alttext" />



<xsl:param name="altname" />



<xsl:param name="hidedetail" />



<xsl:param name="showheader" />



<xsl:param name="showheadercolumn" />



<xsl:if test="$showheader" ddwrt:cf_ignore="1">



<tr id="group{$groupid}" style="display:{$displaystyle}">



<td class="ms-gb" style="background:#cccccc;" colspan="99">



<xsl:choose>



<xsl:when test="$groupid='0' or $groupid='9'">



<xsl:text></xsl:text>



</xsl:when>



<xsl:when test="$groupid='1'">



<xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&amp;nbsp;</xsl:text>



</xsl:when>



<xsl:when test="$groupid='2'">



<xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&amp;nbsp;</xsl:text>



<xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&amp;nbsp;</xsl:text>



</xsl:when>



<xsl:otherwise>



<xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&amp;nbsp;</xsl:text>



<xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&amp;nbsp;</xsl:text>



<xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&amp;nbsp;</xsl:text>



</xsl:otherwise>



</xsl:choose>



<xsl:if test="not($hidedetail)" ddwrt:cf_ignore="1">



<a href="javascript:" onclick="javascript:ExpGroupBy(this);return false;">



<img src="{$imagesrc}" border="0" alt="{$alttext}" name="{$altname}" />



</a>



</xsl:if>



<xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&amp;nbsp;</xsl:text>



<b>



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



</b>



<xsl:if test="$fieldtitle">: </xsl:if>



<xsl:choose>



<xsl:when test="$fieldtype='url'">



<a href="{$fieldvalue}">



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



</a>



</xsl:when>



<xsl:when test="$fieldtype='user'">



<xsl:value-of select="$fieldvalue" disable-output-escaping="yes" />



</xsl:when>



<xsl:otherwise>



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



</xsl:otherwise>



</xsl:choose>



</td>



</tr>



</xsl:if>



</xsl:template>



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



<xsl:param name="fieldtitle" />



<xsl:param name="fieldname" />



<xsl:param name="fieldvalue" />



<xsl:param name="fieldtype" />



<xsl:param name="nodeset" />



<xsl:param name="groupid" />



<xsl:param name="displaystyle" />



<xsl:param name="showfooter" />



<xsl:param name="showfootercolumn" />



<xsl:if test="$showfooter" ddwrt:cf_ignore="1">



<tr id="group{$groupid}" style="display:{$displaystyle}">



<td class="ms-gb" style="background:#cccccc;" colspan="99">



<xsl:choose>



<xsl:when test="$groupid='0' or $groupid='9'"></xsl:when>



<xsl:when test="$groupid='1'">



<xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&amp;nbsp;</xsl:text>



</xsl:when>



<xsl:when test="$groupid='2'">



<xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&amp;nbsp;</xsl:text>



<xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&amp;nbsp;</xsl:text>



</xsl:when>



<xsl:otherwise>



<xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&amp;nbsp;</xsl:text>



<xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&amp;nbsp;</xsl:text>



<xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&amp;nbsp;</xsl:text>



</xsl:otherwise>



</xsl:choose>



<b>



Count : <xsl:value-of select="count($nodeset)" />



</b>



</td>



</tr>



</xsl:if>



</xsl:template>



</xsl:stylesheet>





















Suggested Links:

1) Creating a Custom Search Page and Tabs in the Search Center of SharePoint Server
http://msdn2.microsoft.com/en-us/library/bb428855.aspx

2) Custom XSLT for the Search Core Results Web Part
http://www.u2u.info/Blogs/Patrick/Lists/Posts/Post.aspx?ID=1669


Wednesday, June 6, 2007

Create Custom Search Page in SharePoint Server

1) To start full crawl navigate to following path:
Shared Service Administration: SharedServices1 => Search Settings => Content sources and crawl schedules => Full Crawl

2) To create a new scope navigate to following path:
Shared Service Administration: SharedServices1 => Search Settings => View Scopes => New Scope => “MSDN Content” (New defined scope)

Enter following information in the page:
a) Title and Description: MSDN Content
Target Results Page: Specify a different page for searching this scope
Target results page: * => msdnsearch.aspx

b) Scope Rule Type: All Content

3) To add Tab in Search page navigate to Search tab in Home page.
By default Search Centre has two Tabs -- All Sites and People.

To create a search page navigate to following path --
Home => Search tab => Site Actions => Create Page

Enter following information in the page:
a) Title: MSDN Search
b) Page Layout: (Welcome Page) Search Page
c) Press Button Create.
d) Publish page.

To create a search results page navigate to following path --
Home => Search tab => Site Actions => Create Page

Enter following information in the page:
a) Title: MSDN Search Results
b) Page Layout: (Welcome Page) Search Results Page
c) Press Button Create.
d) Publish page.


4) To set the search and search results page for new tab perform following actions:

Navigate to following path:
Home => Search => Tabs in Search Pages => Sites Actions => View All Sites Contents => Lists => Tabs in Search Pages => New => New Item

Enter following information in page:
a) Tab Name: MSDN
b) Page: msdnsearch.aspx
c) Press OK


Navigate to following path:
Home => Search => Tabs in Search Results => Sites Actions => View All Sites Contents => Lists => Tabs in Search Results => New => New Item

Enter following information in page:
a) Tab Name: MSDN
b) Page: msdnsearch.aspx
c) Press OK

5) Now if you go to following path:
Home => Search => MSDN tab

Write some search keyword in Search text and start the search, the search results will be displayed in All Sites tab.

So, to display the search results in the newly created search results page (i.e. msdnsearchresults.aspx) perform following actions:

Navigate to following path:
Site Actions => Site Settings => Modify All site Settings => Site Collection Administration => Go to top level site settings => Site Collection Administration => Search Scopes => New Display Group

Enter following information in page:
a) Title: MSDN
b) Check only: MSDN Content
c) Press OK


Navigate to following path:
Home => Search => MSDN tab => Site Actions => Edit Page => Search Box => Edit => Modify Shared Web Part => Search Box

Set following settings in it:
a) Scopes Dropdown => Show, don not include contextual scope
b) Miscellaneous => Target search results page URL => “msdnsearchresults.aspx” (newly created search result page)
c) Miscellaneous => Scope Display Group => MSDN
d) Press OK
e) Publish page

6) Now the newly created search tab is ready for use.


Search Page with new tab:


Search Result page:



Suggested Links:

1) Creating a Custom Search Page and Tabs in the Search Center of SharePoint Server
http://msdn2.microsoft.com/en-us/library/bb428855.aspx

Communication between Web Parts

Following steps describes how to create two Web Parts that can communicate with each other:
1) Create a Contract create class.
ITextContract.cs


using System;
using System.Collections.Generic;
using System.Text;

namespace ConsumerProviderWebPart
{
public interface ITextContract
{
string CustomerName { get;set; }
}
}





2) Create a Provider class.

Provider.cs


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace ConsumerProviderWebPart
{
public class Provider : WebPart, ITextContract
{
TextBox tb = new TextBox();
Button btn = new Button();

protected override void CreateChildControls()
{
btn.Text = "Click Me";
btn.Click += new EventHandler(btn_Click);

tb.Text = "Avinash";
CustomerName = tb.Text;

this.Controls.Add(tb);
this.Controls.Add(btn);
}

protected override void Render(HtmlTextWriter writer)
{
EnsureChildControls();
RenderChildren(writer);
}

void btn_Click(object sender, EventArgs e)
{
CustomerName = tb.Text;
}

[ConnectionProvider("Customer Provider")]
public ITextContract ProvideCustomerCommunicationPoint()
{
return this as ITextContract;
}

#region ITextContract Members

private string _CustomerName = "";

public string CustomerName
{
get
{
return _CustomerName;
}
set
{
_CustomerName = value;
}
}

#endregion
}
}




3) Create a Consumer class.

Consumer.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace ConsumerProviderWebPart
{
public class Consumer : WebPart
{
private ITextContract providerWebPart;

[ConnectionConsumer("Customer Consumer")]
public void ReceiveCustomerName(ITextContract provider)
{
providerWebPart = provider;
}

protected override void Render(HtmlTextWriter writer)
{
if (providerWebPart != null)
writer.Write("Value provided is : " + providerWebPart.CustomerName);
base.Render(writer);
}
}
}




4) Strong-named the project.
5) Register the dll in GAC.
6) Make entry in your site web.config file.

web.config

<SafeControl Assembly="ConsumerProviderWebPart, Version=1.0.2713.19492, Culture=neutral, PublicKeyToken=f565ecbfa7f79652" Namespace="ConsumerProviderWebPart" TypeName="*" Safe="True" />



7) Create Provider.webpart file.

Provider.webpart


<?xml version="1.0" encoding="utf-8"?>
<webParts>
<webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
<metaData>
<type name="ConsumerProviderWebPart.Provider" />
<importErrorMessage>Cannot import this Web Part.</importErrorMessage>
</metaData>
<data>
<properties>
<property name="Title" type="string">Provider</property>
<property name="Description" type="string">Provider Web Part.</property>
</properties>
</data>
</webPart>
</webParts>




8) Create Cosumer.webpart file.
Consumer.webpart


<?xml version="1.0" encoding="utf-8"?>
<webParts>
<webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
<metaData>
<type name="ConsumerProviderWebPart.Consumer" />
<importErrorMessage>
Cannot import this Web Part.
</importErrorMessage>
</metaData>
<data>
<properties>
<property name="Title" type="string">Consumer</property>
<property name="Description" type="string">Consumer Web Part.</property>
</properties>
</data>
</webPart>
</webParts>





9) Add both Provider and Consumer web parts in your site.
10) Establish connections between Provider and Consumer web part as shown in following snapshots:

Provider connection:



Consumer connection:



11) Test communication between two web parts by writing some text in Provider’s text box. Then press Provider’s button.



12) Typed text gets displayed in Consumer web part.



Suggested Links:
1) Custom Web Part Connections in SharePoint 2007
http://ablog.apress.com/?p=1300

Developing Custom Web Part

Prerequisites

Make sure you have the following in your development environment:
1. A server with Microsoft Office SharePoint Server 2007 installed.
2. Microsoft Visual Studio 2005 or a similar Microsoft .NET Framework 2.0-compatible development tool installed.

To create the project for the Web Part
1. In Visual Studio 2005, on the File menu, point to New, and then click Project.
2. In Project types, under C#, select Windows.
3. Under Templates, select Web Control Library.
4. In the Name field, type SampleWebPart, and then click OK.



Note : If you are using Visual Studio 2008, then select Class Library project template.


Next you must add the required references to your Web Part project.


To add references to the SearchBDCWebPart project
1. On the Project menu, click Add Reference.
2. On the .NET tab, select each of the following references, and then click OK after each selection:
a. System.Data
b. System.XML
c. Microsoft.SharePoint
Note: “Microsoft.SharePoint”, “Microsoft.Office.Server” and “Microsoft.Office.Server.Search” dlls are present at following locations: C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\ISAPI\

Before you add code for the Web Part, replace the default class file with a new class file.

To create the class file for the Web Part
1. In Solution Explorer, right-click WebCustomControl1.cs, and then click Delete to remove the default class created with the project.
2. On the Project menu, click Add New Item.
3. In the Add New Item dialog box, click Web Custom Control, type Display.cs, and then click Add.




To modify the default code in Display
1. Add the following namespace directives near the top of the code in Display.cs:using System.Web.UI.WebControls.WebParts;
2. In the following code line, replace WebControl with System.Web.UI.WebControls.WebParts.WebPart.public class Display : System.Web.UI.WebControls.WebParts.WebPart

To add the Web Part's child controls and render them
1. Add the following code below the class declaration:




TextBox tb = new TextBox();
Button btn = new Button();
Label lbl = new Label();





2. Override the CreateChildControls method by using the following code:




protected override void CreateChildControls()
{
btn.Text = "Click Me";
btn.Click += new EventHandler(btn_Click);

this.Controls.Add(tb);
this.Controls.Add(btn);
this.Controls.Add(lbl);
}



3. Add a click event for btn, using the following code:




void btn_Click(object sender, EventArgs e)
{
lbl.Text = tb.Text;
}




4. Add following code to render the controls:





protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
EnsureChildControls();
RenderChildren(writer);
}





To deploy the custom Web Part to your site

Note : For development and testing purpose, don't use Central Administration site. You can create your own site from
Central Administration > Application Management > Create or Extend Web Application. For detailed instructions, please refer Create or extend Web applications.

1. Create a strong-named for your Web Part, so you can deploy it in the global assembly cache.

Right click the project in Solution Explorer, and then select Properties.
Select Signing, check Sign the assembly check bob. In the dropdown select New. In Create a Strong Name Key dialog box, enter the key and uncheck Protect my key file with a password.




Press OK and build the solution.
2. Drag-n-drop your project dll to Global Assembly Cache (i.e. “C:\WINDOWS\assembly”).
3. Open the web.config of your site.



Note : In the above figure --- 80 is the port number of my site, it may be different in your case.

Enter following code in it under SafeControls element:


<SafeControl Assembly="SampleWebPart, Version=1.0.2708.19816, Culture=neutral, PublicKeyToken=feb6aaf72958fff3" Namespace="SampleWebPart" TypeName="*" Safe="True" />

For Version and PublicKeyToken, right click the dll in GAC and select Properties.



4. Create a SampleWebPart.webpart, and enter following code in it:


<?xml version="1.0" encoding="utf-8"?>
<webParts>
<webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
<metaData>
<type name="SampleWebPart.Display" />
<importErrorMessage>Cannot import this Web Part.
</importErrorMessage>
</metaData>
<data>
<properties>
<property name="Title" type="string">Sample Web Part
</property>
<property name="Description" type="string">Sample Web Part
that display label.</property>
</properties>
</data>
</webPart>
</webParts>




You can Save SampleWebPart.webpart to any desired location.
To test the custom Web Part
1. Select your site, on which you want to add your Web Part.
2. Under Site Actions, click Edit Page. All the Web Parts in your site gets displayed in Edit mode.
3. Click any Add a Web Part link present in your edit-mode site.
4. Add Web Parts -- Web Page Dialog gets open. In that select Advanced Web Part gallery and options present in the bottom of the dialog box.

5. Add Web Parts window gets open on the right side of your side. Under Browse tab, click the small triangle present in it on the right side. Select Import present in the menu.

6. Import page gets open on the right side of your site. Browse the SampleWebPart.webpart file and upload it by clicking the Upload button.

Your Web Part gets displayed in the Uploaded Web Part section in Import page.

7. Now drag-n-drop your Web Part to any Web Part zone.


8. Now exit the Edit mode by clicking the Exit Edit Mode link present below the Site Actions.

9. Now your Web Part is ready for use.



Appendix

Display.cs


using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

namespace SampleWebPart
{
public class Display :
System.Web.UI.WebControls.WebParts.WebPart
{
TextBox tb = new TextBox();
Button btn = new Button();
Label lbl = new Label();

protected override void CreateChildControls()
{
btn.Text = "Click Me";
btn.Click += new EventHandler(btn_Click);

this.Controls.Add(tb);
this.Controls.Add(btn);
this.Controls.Add(lbl);
}

protected override void Render
(System.Web.UI.HtmlTextWriter writer)
{
EnsureChildControls();
RenderChildren(writer);
}

void btn_Click(object sender, EventArgs e)
{
lbl.Text = tb.Text;
}
}
}






SampleWebPart.webpart


<?xml version="1.0" encoding="utf-8"?>
<webParts>
<webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
<metaData>
<type name="SampleWebPart.Display" />
<importErrorMessage>Cannot import this Web Part.
</importErrorMessage>
</metaData>
<data>
<properties>
<property name="Title" type="string">Sample Web Part
</property>
<property name="Description" type="string">Sample Web Part
that display label.</property>
</properties>
</data>
</webPart>
</webParts>







Suggested Links:

1. Getting Started with Custom Enterprise Search Web Parts:
http://msdn2.microsoft.com/en-us/library/ms564508.aspx

2. Building Custom Enterprise Search Web Parts:
http://msdn2.microsoft.com/en-us/library/ms584220.aspx

3. Walkthrough: Creating a Custom Enterprise Search Web Part:
http://msdn2.microsoft.com/en-us/library/ms551453.aspx

4. Walkthrough: Creating an ASP.NET Web Part for the AdventureWorks Business Data Application Sample:
http://msdn2.microsoft.com/en-us/library/ms558854.aspx

Converting Office Word and Office Excel Forms to Office InfoPath

Ways to convert an Office Word to Office Infopath---

1) Select the Word file that you want to covert.




2) Open Office Infopath and select “Import a Form…” link.



3) Select “InfoPath importer for Word documents”.



4) Browse the Word file that you want to import. To set the Import options click Options button.




5) In Import Options dialog box, select appropriate Layout as per you requirement.



6) After successfully Importing Office Word file, Import Wizard displays the message.



7) Now your Office Word is successfully imported to Office Infopath.



To import an Office Excel, follow same steps, except select “InfoPath importer for Word documents” instead of “InfoPath importer for Word documents”.

Sunday, May 27, 2007

Ways of using Web service from JavaScript


1. Client side <--> ASPX page <--> Web service.
2. Client side <--> HTC file <--> Web service.
3. Client side <--> AJAX <--> Web service.
4. Client side <--> SOAP Request/Response <--> Web service.


1. Create a dummy aspx page that is used by JavaScript to use Web Service functions. JavaScript class calls aspx page and in turn aspx page calls Web Service. Here aspx page use Web Service by adding a Web Reference in project and create a object of Web Service class and process it as normal function calling.


2. HTC Usage –


HTML Page ----



<body>
<div id="service" style="behavior: url(webservice.htc)">

-------------
-------------

</body>





Java Script File ----



function asyncWSCall(strMethodName, strCountryName, boolAsync)
{
strMethodName == "getCurrentPositionData" ; //WebService function name

// Establish the friendly name "WS" for the WebServiceURL
//service.useService("http://localhost/DemoApp/SampleWebService.asmx?WSDL","WS");

// The following uses a callback handler named " processgetCurrentPositionData"
iCallID = service.WS.callService(processgetCurrentPositionData,
strMethodName, strCountryName, boolAsync);
}


function processgetCurrentPositionData(result)
{
-------
-------

document.getElementById('txtAr').value = result.value.xml;
}




Web Service ----


[WebMethod]
public XmlDocument getCurrentPositionData(string countryName, bool boolAsync)
{
------
------
}




3. AJAX Usage –

HTML Page ----


<body>
<form id="form1" runat="server">
<asp:ScriptManager runat="server" ID="scriptManagerId">
<services>
<asp:ServiceReference Path="WSForAJAX.asmx" />
</services>
</asp:ScriptManager>

-----
-----

</body>




Java Script File ----



function wsCallForCurrentPostion()
{
WSForAJAX.getCurrentPositionData(OnSucceededWithContext, OnFailed,"XmlDocument");
}



// This is the callback function invoked if the Web service succeeded.
// It accepts the result object, the user context, and the calling method name as parameters.
function OnSucceededWithContext(result, userContext, methodName)
{
var RsltElem = document.getElementById('txtAr').value;

var readResult;
if (userContext == "XmlDocument")
{
if (document.all)
readResult = result.documentElement.firstChild.text;
else // Firefox
readResult = result.documentElement.firstChild.textContent;

RsltElem.innerHTML = "XmlDocument content: " + readResult;
}
}



// This is the callback function invoked if the Web service failed.
// It accepts the error object as a parameter.
function OnFailed(error)
{
// Display the error.
var RsltElem = document.getElementById("ResultId");
RsltElem.innerHTML = "Service Error: " + error.get_message();
}




Web Service ----



[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
public XmlDocument getCurrentPositionData(string countryName, bool boolAsync)
{
----
----
}




4. SOAP Usage –


Java Script File ----



//Function to create parameter for WebService method.
function createWSParam()
{
var strMethodName = 'getCurrentPositionData' ;
var strSoapContent = '<countryName>' + count4WSCall + '</ countryName >\n'
+ '<boolAsync>' + strCountryName + '</ boolAsync >\n' ;
}





//Function to create SOAP data packet.
function createSOAPData(strMethodName, strSoapContent)
{
var soapAction = 'http://tempuri.org/' + strMethodName ;
var url = 'http://localhost/DemoApp/SampleWebService.asmx' ;
var data = '<?xml version=\'1.0\' encoding=\'utf-8\'?>\n'
+'<soap:Envelope xmlns:xsi=\'http://www.w3.org/2001/XMLSchema-
instance\' xmlns:xsd=\'http://www.w3.org/2001/XMLSchema\'
xmlns:soap=\'http://schemas.xmlsoap.org/soap/envelope/\'>\n'
+ '<soap:Body>\n'
+ '<' + strMethodName + ' xmlns=\'http://tempuri.org/\'>\n'
+ strSoapContent
+ '</' + strMethodName + '>\n'
+ '</soap:Body>\n'
+'</soap:Envelope>' ;
}





//Function to create XMLHttpRequest.
function getXmlHttpObject()
{
var xmlhttp ;
if(window.ActiveXObject)
{
try
{
xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
}
catch (ex)
{
xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
}
}
else if (window.XMLHttpRequest) //For Non-IE
{
xmlhttp = new XMLHttpRequest();
}
}





//Function to send the SOAP Request.
function sendSOAPDataToWebService(xmlhttp, url, data, soapAction)
{
xmlhttp.open('POST', url, true);
xmlhttp.onreadystatechange = processgetSOAPResponseData ;
xmlhttp.setRequestHeader('Content-Type', 'text/xml');
xmlhttp.setRequestHeader('SOAPAction', soapAction);
xmlhttp.send(data);
}





//Function to process the SOAP Response.
function processgetSOAPResponseData()
{
if (xmlhttp.readyState == 4)
{
if (xmlhttp.status == 200) // only if "OK"
{
try
{
if (window.ActiveXObject) // code for IE
{
doc = new ActiveXObject("Microsoft.XMLDOM");

doc.async="false";
doc.loadXML(xmlhttp.responseText);
}
else // code for Mozilla, Firefox, Opera, etc.
{
var parser=new DOMParser();
doc = parser.parseFromString(xmlhttp.responseText,"text/xml");
}

var rootNode = doc.documentElement;
// documentElement always represents the root node

if( rootNode.childNodes[0].childNodes[0].childNodes[0].nodeName
== "getCurrentPositionDataResult" )
{
//Method to process the SOAP data
getCurrentPositionData(rootNode) ;
}
}
catch (ex)
{
}
}
}
}



Web Service ----



[WebMethod]
public XmlDocument getCurrentPositionData(string countryName, bool boolAsync)
{
------
------
}








Suggested Links:

AJAX Example
http://ajax.asp.net/docs/ViewSample.aspx?sref=Sys.Net.SimpleWebService/cs/SimpleWebService.asmx

Use of Xml in AJAX
http://ajax.asp.net/docs/tutorials/CreateSimpleAJAXApplication.aspx
http://ajax.asp.net/docs/ViewSample.aspx?sref=EnhancingJavaScript/cs/Inheritance.aspx

HTC -
http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/samples/internet/behaviors/library/webservice/default.asp

HTC Example -
http://msdn2.microsoft.com/en-us/library/ms531033.aspx

HTC Result Object example --
http://msdn2.microsoft.com/en-us/library/ms531058.aspx

Google