DEFAULT.ASPX: The Site's Home PageThe cornerstone of any SharePoint site is its home page. Although the Module section of ONET.XML enables you to set the home page to anything, DEFAULT.ASPX should be the name of your site definition's home page. As discussed previously, the SharePoint site definition templates place this file in the root of the site definition folder (for example, C:\Program Files\Common Files\Microsoft Shared\web server extensions\60\TEMPLATE\1033\STS). DEFAULT.ASPX can be modified to your heart's desire. Additional web part zones could be added, icons could be changed, the Quick Launch could be removed, and the list goes on. To help facilitate your own modifications, let's spend some time deconstructing STS's DEFAULT.ASPX. A typical instance of DEFAULT.ASPX from the STS site definition is shown in Figure 2.24. The major elements include the top blue navigation bar, the bar immediately under navigation bar, the Quick Launch, and the Left and Right web part zones. Figure 2.24. DEFAULT.ASPX Design view.Top Navigation BarThe code that generates the top blue bar is shown in Listing 2.25. The code generates a three-column HTML table row. The first column is a SharePoint team logo. The second column represents the navigation bar we discussed in ONET.XML's NavBars section. The last column is a connection to the parent site, or the portal if the site is the topmost site in the site collection. The content of second and third columns is dynamically generated by web controls from the Microsoft.SharePoint. WebControls namespace. Listing 2.25. DEFAULT.ASPX Top Bar
Logo, Site Title, Search Box, and SharePoint Modify Page LinkImmediately underneath the top blue bar is a row that contains the home logo, site title and location, search box, and modify shared/personal page link. That code is shown in Listing 2.26. What might be surprising to learn is that neither the circular home logo nor the "Home" page title is dynamically defined. They are simply coded as static links. Thus, it is very straightforward to reference another URL for the home icon or change the page title to something else. The only things that are dynamically defined within that row are the site's description, the search box, the modify shared/personal page link, and the authentication button. These dynamic generations are powered by web controls from the Microsoft.SharePoint.WebControls and Microsoft.SharePoint.WebPartPages namespaces. As you build your own site definition templates, you should consider upgrading Windows SharePoint Services' weak search support. WSS only enables you to search the current site. It does not search subsites or parent sites. Because it does not declare this weakness, users usually do not realize that content might exist in a subsite even though it did not show up in the search results. Although this weakness is being solved in the next version of Share-Point, Microsoft has released an upgraded search box as an interim solution. Specifically, Anthony Petro's MSDN article "Creating a Site Context Search Box that Uses SharePoint Portal Server Search Results" includes an updated search box that can be integrated into DEFAULT.ASPX or any other site definition page. Anthony's search web part enables the user to select the context (site, site collection, or all content indexed by SharePoint Portal Server) of his or her search and uses SharePoint Portal Server to generate the results. The web part posts the search query along with its context to SharePoint Portal Server's search page through the querystring. The next version of Share-Point will expand on this idea. Listing 2.26. DEFAULT.ASPX Logo, Title, Search Box, Settings Link, and Authentication Button
Quick Launch BarOne would expect the Quick Launch bar to be a single web part. However, it is composed of several web parts, one for each list type. The code snippet in Listing 2.27 provides a window into how the Documents section of Quick Launch is generated, and it is representative of the other sections. The Documents text is statically defined and links to VIEWLSTS.ASPX with a querystring parameter. The querystring parameter filters the page for document libraries. Listing 2.27. DEFAULT.ASPX QuickLaunch
The site's document libraries are enumerated immediately below the static Documents text. This dynamic generation is made possible through the Microsoft.SharePoint.WebControls.Navigation web control class. The site's document library instances are formatted with regard to a NavBar defined within ONET.XML. In the current case, Documents links back to the NavBar with an ID of 1004. The Documents NavBar is detailed in Listing 2.28. Listing 2.28. Documents NavBar
Site Description and Web Part ZonesThe last elements are the description property and web part zones as shown in Listing 2.29. The description is generated from the ProjectProperty class with a Property attribute set to Description. Recall that the site's title was rendered in the same fashion except for the Property attribute being set to Title. Listing 2.29. DEFAULT.ASPX Description and Web Part Zones
DEFAULT.ASPX has two web part zones. In our example, we have Left and Right web part zones. Both web parts have their FrameType, ID, and Title attributes specified. These and other attributes are defined in Table 2.13.
As you start to experiment with adding web part zones to your pages, you will discover that WebPart and WebPartZone controls must live in a runat='server' HtmlForm. You will therefore have to move the form tag to surround all WebPart and WebPartZone controls. Depending on where you place the opening and closing form tag, you can run into a somewhat confusing error: The Controls collection cannot be modified because the control contains code blocks (that is, <% . . . %>). ASP.NET complains because ASPX code blocks (<% . . . %>) cannot exist within a form tag that is run at the server. Assuming you didn't put any additional ASPX code blocks into your DEFAULT.ASPX page, the only ASPX code blocks are from Quick Launch. Quick Launch uses the code blocks to determine the LCID of the SharePoint server. This value is then embedded within a dynamically generated URL. Your options now include building a custom web control to render the LCID, removing the Quick Launch from the home page, hard coding the LCID into the site definition, using client-side JavaScript, or some hybrid. Whichever option you choose, it should be relatively easy to navigate around this issue. |