Sample Codes

This section describes two options for Web Parts that use relative URLs: ASP or VBScript code. These options describe a stand-alone Web Part. The ASP and VBScript code samples enable you to use the same Web Part when accessing the server by using NetBIOS, internal FQDN, or external FQDN. The samples contain two relative links and some very basic ASP code.

Both code samples perform the same task. The samples are provided to demonstrate two ways to perform the same task.

Using the Sample ASP or VBScript Code 

You can create your Web Part from ASP or VBScript code. The advantages of referencing an ASP or VBScript page are:

  • You can use existing ASP or VBScript code without changing it.
  • All code is executed from the client, reducing the load on the server.
  • The Web Part is isolated, preventing any interaction with other Web Parts.

The disadvantages of referencing an ASP page or a VBScript page are:

  • The code is not easily portable.
  • The Web Part cannot interact with other Web Parts.
  • The Web Part cannot function if you are using Netscape Navigator as your browser.

To use sample ASP code as your Web Part:

  1. Create a file named User.asp containing the following code:
     <HTML> <BODY> <% Response.write request.servervariables("Logon_User") %> <p> <A Href="../" Target="new">Home</a><p> <A Href="../Portal/Document%20Library/" Target="new">Document Library</a> </BODY> </HTML> 
  2. Navigate to the Portal folder in the workspace.

    The Portal folder is a hidden folder.

  3. Copy User.asp into the Portal folder.
  4. Navigate to the Home page of the dashboard site.
  5. Click Content.
  6. Click Create a New Web Part.
  7. On the Settings page for the Web Part, select the Get content from the following link check box.
  8. Type /workspace_name/Portal/User.asp under the Get content from the following link check box.
  9. Select the Isolate this Web Part's content from the other Web Parts check box.
  10. Click Save to close the Settings page for the Web Part.
  11. Click Save to close the Content page for the Home page.

Using the Sample Web Part Code

You can create a stand-alone Web Part containing relative links.

The advantages of using a stand-alone Web Part are:

  • The code executes more quickly than a non-isolated ASP page or VBScript page.
  • The code is portable and reusable on any dashboard.
  • The Web Part can interact with other Web Parts.

The disadvantages of using a stand-alone Web Part are:

  • The server load increases.
  • You must migrate existing code to meet the specification for Web Parts for the digital dashboard.
  • The Web Part is difficult to debug once it is deployed. It is recommended that you include copious error handling in your code.

To use a sample Web Part:

  1. Create a file named TestWithRelativeURLs.dwp containing the following code:

    Long commented lines and some code lines wrap to the next line in the following sample. For best results, copy the code sample and paste it directly into Microsoft Notepad.

     <?xml version="1.0"?> <WebPart xmlns="urn:schemas-microsoft-com:webpart:" version="1.0.0">   <Title>Web Part Sample with relative URLs</Title>   <Description>How to create a Web Part with relative URLs</Description>   <Content><![CDATA[ 'Generic Web Part Function. REQUIRED. Function GetContent(nod)   Dim strWorkspaceUrl 'Variable to store calculated URL of user   On Error Resume Next   'BEGIN COMMENTS   'NOTE:     ExtractWorkspaceURL and GetServerVariable are function calls to TahoeUtils.inc.    '          We cannot guarantee backward compatibility with future SPs or versions of SharePoint Portal Server.   '          It is recommended that you create your own standard include library to retrieve the URL of the user.   '          Once you create your library, include it in DashboardExtensions.vbs (see DDRK for more information).   'IMPORTANT: DO NOT modify TahoeUtils.inc in any way. Modifications may break your portal and are not supported.   'END COMMENTS   strWorkspaceUrl = ExtractWorkspaceUrl(GetDBProtocol() & _    GetServerVariable("SERVER_NAME") & GetServerVariable("URL"))   If Err.Number <> 0 Then Exit Function   strHtmlRet = request.servervariables("Logon_User") & vbCRLF    'Build up HTML output to a string   'Add a relative URL link with strWorkspaceUrl   strHtmlRet = strHtmlRet & "<p>"   strHtmlRet = strHtmlRet & "<a target=new href=""" & _    strWorkspaceUrl & "/Portal"">" & vbCRLF    strHtmlRet = strHtmlRet & "Portal" & vbCRLF   strHtmlRet = strHtmlRet & "</a>" & vbCRLF   'Add another link   strHtmlRet = strHtmlRet & "<p>"   strHtmlRet = strHtmlRet & "<a target=new href=""" & _    strWorkspaceUrl & "/Portal/Document Library"">" & vbCRLF    strHtmlRet = strHtmlRet & "Document Library" & vbCRLF   strHtmlRet = strHtmlRet & "</a>" & vbCRLF   'Return string to Dashboard   GetContent = strHtmlRet End Function ]]></Content>   <ContentType>1</ContentType>   <IsVisible>1</IsVisible>   <AllowRemove>1</AllowRemove>   <HasFrame>1</HasFrame>   <AllowMinimize>1</AllowMinimize>   <FrameState>0</FrameState>   <RequiresIsolation>0</RequiresIsolation>   <CacheBehavior>0</CacheBehavior>   <CacheTimeout>0</CacheTimeout>   <DetailLink></DetailLink>   <CustomizationLink></CustomizationLink>   <IsIncluded>1</IsIncluded>   <PartOrder>0</PartOrder>   <Zone>3</Zone> </WebPart> 
  2. Navigate to the home page of the dashboard site.
  3. Click Content.
  4. Click Import a Web Part File.
  5. Import TestWithRelativeURLs.dwp.
  6. Click Save to close the Content page for the Home page.


Microsoft Sharepoint Portal Server 2001 Resource Kit
Microsoft SharePoint(TM) Portal Server 2001 Resource Kit (Examples & Explanations Series)
ISBN: 0735615624
EAN: 2147483647
Year: 2001
Pages: 231

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