Integrating with SharePoint Portal Server

                 

 
Special Edition Using Microsoft SharePoint Portal Server
By Robert Ferguson

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


SharePoint provides a wide range of possibilities for integration. It offers a platform for integration with other products such as Office XP and Exchange server, and support for the development of a variety of Web Parts using almost any type of programming language. Business people and knowledge experts can easily participate in creating Web Parts by just using Office XP. They can use the regular Office XP Word to create documents and save them as a Web Part, or create Excel spreadsheets or PowerPoint presentations as they used to and publish them on the Web, without having extensive knowledge about Web development. On the other hand, developers can use their existing skills such as HTML, Dynamic HTML, VBScript, JavaScript, XML, and XSL to create a more polished and advanced Web Part. In the following sections, we are going to show how you can use your existing skills to create Web Parts.

"Date" Web Part

The purpose of the Date Web Part is to show the current date in our Home dashboard. This is an easy few lines of code that shows the current date in your dashboard. To create the Date Web Part, you basically need a few lines of VBScript code, as shown in Listing 15.1.

Listing 15.1 VBSCript Code for Date Web Part
 Function getContent(xml)   Dim strContent   strContent = "<DIV style=""font-size: 100%"">"   strContent = strContent & FormatDateTime(Now(), 1)   strContent = strContent & "</DIV>"   strContent = strContent & "<HR>"   getContent = strContent End Function 

The getContent function shows the current date and returns in the format of Weekday, Month Name Day, Year.

Notice that we have used the Now() built-in date function to get the current date and pass it as a parameter to another VBScript function FormatDateTime(), with argument 1 as the second parameter that generates the current date in the desired format (for example, Sunday, November 18, 2001).

NOTE

All the Web Parts are processed and rendered by the dashboard factory (dashboard.asp). The dashboard factory allows Web Parts to get their content from WSS, or run queries and scripts through the GetContent() function. For more information about Dashboard Architecture, see

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/spssdk/html/_dashboard_architecture.asp


To make a Web Part from these couple lines of VBScript code, we need to

  1. From the main menu bar at the upper right corner of the SharePoint dashboard, click Content. Then, from the Content dashboard, click on Create New Web Part, located at the bottom of the screen under the Import or Create section (see Figure 15.1).

    Figure 15.1. The content of the "Home" Web Part.

    graphics/15fig01.jpg

  2. In the General Settings of the Web Part Settings dashboard, enter Date Header for the Name of the Web Part, and for the Description of the Web Part, enter The Date Header Web Part displays the current date at the top of your digital dashboard. Since the output is a small message, we do not want to show it in a frame, so make sure the check box for Display this Web Part in a frame is not checked.

  3. Select Top banner for the position of the Web Part.

  4. For the rest of the settings in the General Settings section, accept the defaults.

  5. In the Advanced Settings section, select VBScript from the drop-down menu as the type of content.

    Figure 15.2. The General Settings for the "Date" Web Part.

    graphics/15fig02.jpg

  6. Click on the Embedded content text area box, and enter the code shown in Listing 15.1.

    Figure 15.3. The Advanced Settings for the "Date" Web Part.

    graphics/15fig03.jpg

  7. Accept the default settings for the rest of the options in the Advanced Settings section. Click on Save in the Settings dashboard, and click on Save again in the Content dashboard. In the Home dashboard, you can see the date on the left banner. You may use the Layout dashboard and move the Date Web Part to the upper-right banner of the Home dashboard. Figure 15.4 shows the final view of the Date Web Part.

    Figure 15.4. Using VBScript to create a simple Date Web Part.

    graphics/15fig04.jpg

"Welcome User " Web Part

The purpose of this Web Part is to display the name of the user who has logged in to the SharePoint Portal Server.

This is another line of code, and an easily developed Web Part.

To use this Web Part, your SharePoint must require user authentication, and obviously if SharePoint is configured for public access without any authentication, this Web Part cannot be used. The one line of code is

 getContent = "Welcome " & mid(GetServerVariable("AUTH_USER"), instr(GetServerVariable( graphics/ccc.gif "AUTH_USER"), "\")+1) 

When you set Basic Authentication as a mechanism for controlling access to your Web Part, the users' credentials are stored as server variables AUTH_USERand if the domain name is used as part of the username (for example, domain\username) the part after "\" will be the username. Using Mid and GetServerVariable functions, we can extract the username. This way we can get the username and concatenate it with the word "Welcome", so we can show "Welcome User" at the Home dashboard. To make this code into a Web Part requires the same steps as those for the Date Web Part. The final view of this Web Part is shown in Figure 15.5.

Figure 15.5. The "Welcome User" Web Part displays the name of user who has logged in to the SharePoint Portal Server.

graphics/15fig05.jpg

You can apply your desired font size or color to the Welcome User string by using an HTML DIV tag, as seen in the code for the Date Web Part.

GetServerVariable is a function in dbUtil.vbs. It uses request.servervariable to get the value "AUTH_USER". Listing 15.2 shows the GetServerVariable source code.

NOTE

dbUtil.vbs is a VBScript file located in the Portal/Resources Web folder. It has many functions and utilities that are used in different places in the SharePoint code. You can use Web Folder view to access this file and copy it to a different folder to take a look at it. The Portal folder is a hidden folder; to see the hidden files and folders make sure that you have enabled viewing of hidden files.


Listing 15.2 The GetServerVariable Is a Reusable Function Located in dbUtil.vbs File in Resources Subdirectory of SharePoint Portal Server
 Function GetServerVariable(strVariable)     On Error Resume Next     Dim strTmp     Dim nCodePage     nCodePage = Session.CodePage     Session.CodePage = 0    ' CP_ACP     strTmp = Request.ServerVariables(strVariable)     Session.CodePage = nCodePage     GetServerVariable = strTmp   End Function 

                 
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