Welcome Guest!
Create Account | Login
Locator+ Code:

Search:
FTPOnline Channels Conferences Resources Hot Topics Partner Sites Magazines About FTP RSS 2.0 Feed

Free Trial Issue of Visual Studio Magazine

email article
printer friendly
get the code
more resources

Build a SharePoint Web Part
Learn how to leverage built-in SharePoint functionality by creating a customizable sun times calculator.
by Ken Cox

August 20, 2004

Technology Toolbox: VB.NET, ASP.NET, Windows Server 2003, Windows SharePoint Services or SharePoint Portal Server 2003

One of SharePoint Portal Server's selling points is that it provides broad customization at all levels, from a corporation's home page down to a single user's personal page. Without having to write code, users can assemble content, design their pages, and rearrange sections to reflect their tasks, role, personality, and location. Personalization is especially effective in SharePoint Web Parts, which are small pluggable units that can generate individual views of data, lists, and alerts. Personalization is more than the option to show, hide, or collapse a canned Web Part; it's also the ability to set individual values and parameters, save them, and restore them at the next logon.

ADVERTISEMENT

I'll show you how easy it is to piggyback on the free, built-in SharePoint functionality that lets users supply their own data to a custom Web Part. The sample project included with this article calculates the sunrise and sunset times based on the longitude, latitude, and time zone a user provides. When the Web Part is installed and configured on the page, it displays the sun times for the current day and location (see Figure 1).

The interface displays the tool pane when users modify a Web Part (see Figure 2). This is a built-in utility section where administrators and regular users (if they're granted sufficient permissions) can provide parameters, defaults, and other settings for the components that make up the page.

I'll also show you how to enable customization so SharePoint maintains a user's settings in his or her personal storage area. After I discuss the basic details about building the Web Part, I'll show you how to deploy the package so any user can drop it on a personal page.

Note that the sample code includes advanced formulas and algorithms that generate the sun times, but I don't discuss those functions here. The complex code comes from the National Oceanic and Atmospheric Administration (NOAA) Surface Radiation Research Branch, a U.S. government agency, and is available on the NOAA Web site and on GotDotNet (see Additional Resources). For the limited purposes here, I've stripped the sun times code to its bare essentials and assembled it into two classes: calculations and SunRoutines. Both are included in the downloadable project. You treat these classes as black boxes into which you push parameters and get back the values to display:

sunrout = New SunRoutines
sr = New calculations
sr = sunrout.GetSunriseSunset _
   (location, latitude, longitude, _
   timezone, IIf(dst = True, 1, 0), _
   zenithvalue)

SharePoint Web Parts are ASP.NET server controls with some added features that make them work well in the SharePoint context. Designing these controls by hand can be tricky, but Visual Studio 2005 promises to catch up to the Web Part technology by including a WYSIWYG designer. For the time being, you can get by nicely with the available tools and documentation. Microsoft provides a downloadable Web Part library template that gets you started in Visual Studio .NET 2003 and an SDK with samples and an API reference (see Additional Resources).




Back to top














Java Pro | Visual Studio Magazine | Windows Server System Magazine
.NET Magazine | Enterprise Architect | XML & Web Services Magazine
VSLive! | Thunder Lizard Events | Discussions | Newsletters | FTP Home