Active Directory Connection

                 

 
Special Edition Using Microsoft SharePoint Portal Server
By Robert  Ferguson

Table of Contents
Chapter  15.   Create Web Parts Using Your Existing Code


In the Employee Locator Web Part, we used the strConnection variable to connect to the SQL Server database. This variable provided required information such as OLEDB provider, name of the SQL Server, database name, and user credentials for accessing the database. To connect to the Windows 2000 Active Directory, we need similar information. In this case, the name of the Active Directory domain is required so we can connect to the Active Directory. The name of the domain controller is a variable that can be changed for different environments, so I pass the Active Directory connection information as a parameter. In this example, my domain controller is dianatr.cop.cpqcorp.net and I pass this as strConnection to a VB component.

 strConnection = "dianatr.cop.cpqcorp.net" 

Creating VB Components

For the Active Directory Lookup Web Part, I can use the same VBScript code used for the third version of Employee Locator, and just change the strConnection information (Listing 15.9).

Listing 15.9 The VBScript Code for the Active Directory Lookup Web Part
 Option Explicit Dim strConnection Dim oEmployee Dim strRst Dim xmlBody Dim displayweb Dim strBody strConnection = "dianatr.cop.cpqcorp.net" Set oEmployee = CreateObject("EmployeeAD.clsEmployeeAD") strRst = oEmployee.RetrieveEmployeeAD(strConnection) Set xmlBody = CreateObject("MSXML2.domdocument") xmlBody.async = False xmlBody.LoadXML strRst Set displayWeb = CreateObject("MSXML2.domdocument") displayWeb.async = False displayWeb.Load "E:\Projects\SharePointBook\Chapter 15\submitted-v1\employeeAD.xsl" strBody = xmlBody.transformNode(displayWeb) 

As shown in the previous listing, I have used the EmployeeAD component, which has a RetrieveEmployeeAD method for collecting the user information and returning it as an XML string. Listing 15.10 shows the RetrieveEmployeeAD public function.

Listing 15.10 The Code for RetrieveEmployeeAD, Using Active Directory Provider to Connect to Active Directory
 Public Function RetrieveEmployeeAD (ByVal strConnection As String) As String     Dim strSQL As String     Dim oConn As New ADODB.Connection     Dim rs As New ADODB.Recordset     Dim oStream As New ADODB.Stream     Dim mdsPath As String     'this is the ADSI-OLEDB provider name     oConn.Provider = "ADsDSOObject"     oConn.Open "Active Directory Provider"     mdsPath = "'LDAP://" & strConnection & "'"     strSQL = "select  mail, name, givenName, sn from " & mdsPath & " where graphics/ccc.gif objectCategory='person' AND objectClass='user' order by sn asc "     With rs         .ActiveConnection = oConn         .CursorLocation = adUseClient         .CursorType = adOpenStatic         .LockType = adLockBatchOptimistic         .Source = strSQL         .Open         .ActiveConnection = Nothing     End With     rs.Save oStream, adPersistXML     RetrieveEmployeeAD = oStream.ReadText(adReadAll)     Set rs = Nothing     Set oConn = Nothing End Function 

To create this component, we need to follow the same steps that were mentioned for creating the Employee component in the third version of the Employee Locator; the final product would be EmployeeAD.dll.

Active Directory Lookup XSL File

The XML data string returned from the EmployeeAD component has the same structure as the one used in the Employee Locator. The only difference is the name of data attributes, so we need to make some minor changes in the XSL file used for the Employee Locator. For this example, we have retrieved the UserID that is used for logging in to the domain, as well as the user's name and email address. Listing 15.11 shows the XSL file used for the Active Directory Lookup Web Part.

Listing 15.11 The XSL Code for Transforming Employee Data from XML to HTML Format
 <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">   <xsl:template match="/">     <HTML>       <BODY>        <TABLE width="420">         <tr bgcolor="Black">          <td width="130"><font face="Verdana" size="1" color="white"> <b>USER NAME</b></ graphics/ccc.gif font></td>          <td width="110"><font face="Verdana" size="1" color="white"> <b>NAME</b></font></ graphics/ccc.gif td>          <td width="150"><font face="Verdana" size="1" color="white"> <b>EMAIL</b></ graphics/ccc.gif font></td>         </tr>     <xsl:for-each select="xml/rs:data/z:row">     <TR bgcolor="#ffdead">      <TD><font face="Verdana" size="1" color="black"><xsl:value-of select="@sn"/></font></ graphics/ccc.gif TD>      <TD><font face="Verdana" size="1" color="black"><xsl:value-of select="@name"/></ graphics/ccc.gif font></TD>      <TD><font face="Verdana" size="1" color="black"><xsl:value-of select="@mail"/></ graphics/ccc.gif font></TD>     </TR>     </xsl:for-each>        </TABLE>       </BODY>     </HTML>   </xsl:template> </xsl:stylesheet> 

To make the Active Directory Lookup Web Part, we follow the same steps used for creating the Employee Locator 2 and 3 Web Parts. We select VBScript for Content Type, and insert the code shown in Listing 15.10 in the Embedded Content text area box, located in the Advanced Settings section of New Part “ Settings .


                 
Top


Special Edition Using Microsoft SharePoint Portal Server
Special Edition Using Microsoft SharePoint Portal Server
ISBN: 0789725703
EAN: 2147483647
Year: 2002
Pages: 286

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net