Skip to Main Content
Essential SharePoint
book

Essential SharePoint

by Jeff Webb
May 2005
Beginner content levelBeginner
336 pages
10h 14m
English
O'Reilly Media, Inc.
Content preview from Essential SharePoint

Creating Web Part Appearance

The core of the web part template code is the RenderWebPart method. This method is called just before the control is disposed and it determines the appearance of the part on the page.

To create this appearance, you write HTML to the output object. For example, the following code displays a simple table containing information about the current user's identity:

     ' Requires this line at class level
     ' Imports System.Security.Principal
     Protected Overrides Sub RenderWebPart _
       (ByVal output As System.Web.UI.HtmlTextWriter)
         ' Get the User identity.
         Dim user As IPrincipal = Me.Context.User
         ' Write table to output
         With output
              .Write("<TABLE id='tblUser'>")
              .Write("<TR><TD>Authenticated</TD><TD>")
              .Write(user.Identity.IsAuthenticated())
              .Write("</TD></TR><TR><TD>User name</TD><TD>")
              .Write(user.Identity.Name())
              .Write("</TD></TR><TR><TD>Authentication type</TD><TD>")
              .Write(user.Identity.AuthenticationType())
              .Write("</TD></TR><TR><TD>Code is impersonating</TD><TD>")
              .Write(WindowsIdentity.GetCurrent().Name)              .Write("</TD></TR><TR><TD>Request language: </TD><TD>")
              .Write(context.Request.UserLanguages(0))
              .Write("</TD></TR><TR><TD>Request host: </TD><TD>")
              .Write(context.Request.UserHostName)
              .Write("</TD></TR><TR><TD>Request IP: </TD><TD>")
              .Write(context.Request.UserHostAddress)
              .Write("</TD></TR></TABLE>")
         End With
     End Sub

At runtime, the preceding web part displays user information in a two-column table, as shown in Figure 9-5.

Figure 9-5. Rendering UserInfo web ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

SharePoint User's Guide

SharePoint User's Guide

Infusion Development Corp. (Infusion Development Corporation)
Beginning SharePoint® 2010: Building Business Solutions with SharePoint

Beginning SharePoint® 2010: Building Business Solutions with SharePoint

Amanda Perran, Shane Perran, Jennifer Mason, Laura Rogers

Publisher Resources

ISBN: 0596008805Errata Page