C H A P T E R  4

Managing Web Parts

Web parts are an important piece for quickly creating dynamic and robust SharePoint sites. SharePoint 2010 provides several web parts to help you quickly get started. Although you can add web parts to web pages in the browser, it is much quicker and more efficient to create web part pages in SharePoint Designer.

You will learn about the following topics in this chapter:

  • Creating Web part pages, master pages, and wiki pages
  • Working with Web parts and controls
  • Using the Web Part Gallery
  • Adding and configuring web parts
  • Using personal views vs. shared views
  • Connecting web parts
  • Exporting web parts
  • Fixing broken pages

If lists are the foundation for the data stored in SharePoint, web parts are the foundation for the presentation of that data to the user. One of the great benefits of SharePoint is that it enables an end user to create portals and web sites without programming skills, by using only the web browser. By using lists to store content and preprogrammed web parts to display data, almost anyone can create dynamic, content-rich web sites.

Web parts are small applications that perform a specific function on a web page. You can have a web part that displays the contents of a list. You can have a web part that displays the status of a project. Web parts are self-contained so that they are portable, which enables them to be used multiple times in a web site. For example, you could have a List View web part display only the top five new items in the list on the welcome page of the site, but display all of the list items in a details page—same web part, different presentation.

This chapter covers the web parts available to users in the different versions of SharePoint 2010. You will learn about the pages that can and cannot contain web parts. You will also learn how to connect web parts to provide a richer user experience. Then finally, you’ll see how you can export your web part configurations to reuse them on other sites.

Creating Pages for Web Parts

A discussion about web parts can’t really begin without talking about the pages they can be placed on, and the pages they can’t. SharePoint Designer 2010 provides the ability to create many types of files you can use on a web site:

  • Web content pages
    • Master pages
    • Page layouts
    • Web part pages
    • Wiki pages
    • ASPX pages
    • HTML pages
  • Artifacts
    • CSS
    • JavaScript
    • XML
    • Text files

This section covers the web content pages. Chapters 69 provide detailed discussions on the types of artifacts that you can create in SharePoint Designer 2010.

images Note SharePoint sites come in two flavors: publishing and nonpublishing. The Publishing Site template, combined with the publishing features, contains specific functionality to manage the content publishing process, such as content approval, versioning, and publishing. It uses three files to create a web page: the master page, the page layout, and the content page. Publishing is covered in detail in Chapter 7.

Master Pages

In order to provide your site with a consistent look and user experience, SharePoint employs ASP.NET master pages. A master page defines the basic layout, structure, and functionality of the site content. The master page provides placeholders to indicate where content can go. When a new page is created based on the master page, the new page content and the master page are merged by replacing the placeholders with the page content. SharePoint 2010 uses one main master page called v4.master, but you can create your own master pages and use them as your default master page.

To create a new master page, you can click the All Files link in the Navigation pane and then select Blank Master Page from the New File menu on the Ribbon. It is important to remember that when you create a new master page in SharePoint, it is going to expect certain placeholders, such as PlaceHolderMain, to exist in order to display the site content on the page. It is because of these requirements that most people begin with a copy of v4.master when making their own master page. Working with v4.master is covered more in Chapter 6.

Wiki Pages

Wiki pages are a new page type in SharePoint 2010. These special SharePoint web part pages contain a SharePoint embedded form field, or content editor. With this type of form field, you can edit the content either in SharePoint Designer or the browser. You can also add other web parts to the page. Although it’s possible to create a wiki page in SharePoint Designer, it is much more efficient to create the page in the browser. A simple way of creating a new page in SharePoint Designer is to make a copy of an existing wiki page and then rename it.

EXERCISE 4-1. CREATE AND EDIT A NEW WIKI PAGE

Web Part Pages

Web part pages are special web pages in that they specify different zones that can contain content. These zones allow end users to add web parts to pages and customize pages to their needs. SharePoint Designer provides web part page layout templates that you can select right out of the box, as you can see in Figure 4-8. You can also create your own layouts. Web part pages enable this functionality through the use of web part zones.

Although you can place web parts outside a web part zone when using SharePoint Designer in Advanced edit mode, web part zones are the only area that a user can edit in the browser. Web parts placed outside a web part zone are referred to as static web parts, and those web parts placed inside web part zones are dynamic web parts. Figure 4-9 shows web part zones on a page.

images

Figure 4-9. Web part page showing web part zones

ASPX and HTML Pages

SharePoint Designer 2010 provides the ability to create and edit ASPX pages and standard HTML pages. This functionality is provided in case there is a need to create or edit regular web pages as part of a site. These pages do not automatically inherit the site master page and can be edited only in Advanced mode. You cannot put web parts on them unless you manually add a web part manager and web part zones (thereby creating a web part page), which is beyond the scope of this chapter.

Using the Web Part Gallery

The Web Part Gallery, shown in Figure 4-10, is a special document library that resides at the root of the site collection and contains a list of all of the web parts that can be used for the site collection. You can upload new web parts here or you can export your other web part configurations and upload them here. An easy way to find the Web Part Gallery is to add /_catalogs/wp to the end of your site collection URL. For example, if your site collection is at http://sharepointdesigner2010, then the Web Part Gallery is at http://sharepointdesigner2010/_catalogs/wp.

images

Figure 4-10. Web Part Gallery

The exact web parts that in you have available to you are different depending on the version of SharePoint you have installed and the features you have activated. Microsoft does not provide a specific list of which web parts are in which version, but a quick search of the Internet turns up a couple of comprehensive lists.

To add a new web part to the Web Part Gallery, navigate to the Web Part Gallery by clicking Site Actions images Site Settings images Galleries images Web Parts. Once there, click the Documents tab of the Ribbon and select New Document. A list of all available web parts registered with the web.config file will be displayed. Select the check boxes of the web parts you wish to install and click the Populate Gallery button.

images Note To enable web parts in the site collection Web Part Gallery, the web parts must be properly installed and registered with the site collection’s web.config file. This can be accomplished manually or by a deployment package, usually as part of a WSP file. More information on deployment can be found at http://technet.microsoft.com/en-us/library/cc261736.aspx.

Adding and Configuring Web Parts on a Page

To use web parts, you first need to have a container to put them in. As mentioned earlier, SharePoint has page templates with web part zones already defined. When you create a web part page based on one of these templates, it is saved in a special document library called Site Pages that is created automatically when the site is created. You can also create web pages in other document libraries and in folders within those document libraries. Once you create a page, you can place web parts in defined web zones.

With SharePoint Designer, you can also add or delete web part zones. You can edit pages in Basic mode or Advanced mode. In Basic mode, you can add or remove web parts from a page but you can’t modify layouts. In Advanced mode, you have full control over the page, but it is done at a price. When you edit pages in Advanced mode, you separate the file from its original site definition file that resides on the file system. Performance is affected because the modified file is stored in the content database. When the page is requested, it is read from the content database each time, which is slower. If you find that you accidentally modify a page in Advanced mode and you wish to go back to its original form, you can select Reset to Site Definition anytime to get rid of your changes.

EXERCISE 4-2. CREATE A WEB PART PAGE

images

Figure 4-16. Final web part page

Working in a Personal View vs. a Shared View

Normally, when a user navigates to a web part page, that user is viewing the Shared view of the page. This view is the same view that everyone else sees. SharePoint provides a way for a user to customize the page and the different web parts on the page to give them a Personal view of the page. This is one of the powerful aspects of SharePoint. Each user can have a different experience, within limits, based on the web parts they decide to place on the web part page. This functionality is achieved through the Personal menu attached to the person’s login name. All personal configuration information is stored separately for each user. Personalization can be done only from the browser, but you can enable or restrict some personalization features in SharePoint Designer. For example, a user might want to display an RSS feed that applies to his job, but you don’t want users to be able to delete an RSS feed to your corporate site.

EXERCISE 4-3. CREATE A PERSONAL VIEW OF A WEB PART PAGE

Connecting Web Parts

Because web parts by design are meant to be portable, they are programmed to live on any page. But being able to place these web parts on a page by themselves would be boring. It would make web sites more interactive and more dynamic if the web parts could communicate with each other and share data. SharePoint provides that functionality with web part connections. Connecting web parts have the ability to provide values to another web part on the same page or another page or accept data from another web part. The data accepted can be used as filter data to further filter a list or as parameter values. Web parts can exchange single values or multiple values. Not all web parts can be connected, but for those that can, they can help create a rich user interface.

EXERCISE 4-4. CONNECTING WEB PARTS

images

Figure 4-35. Select Filter Value dialog box

Exporting Web Part Configurations

Often times, you might want to save the configuration of a web part to use it on other pages. You can export the configuration of a web part and then import it into another page. You can also import it into another Web Part Gallery file.

To export a web part, open the web part page in SharePoint Designer. Select a web part and then click To Site Gallery on the Web Part tab. A dialog box will open, prompting you to supply a Name and Description for your configuration. It is important that the name be unique and the description detailed so you know exactly what configuration you are saving. Also, by giving it a unique name, you avoid future confusion when selecting web parts for a new page. The dialog box also gives you the opportunity to change the configuration before saving it to the Web Part Gallery.

Once the web part is exported to the Web Part Gallery, it will be available in the drop-down Web Part menu under Custom Web Parts. When you select that custom web part for another page, it will already be configured.

You can also export a web part configuration to a file by clicking the To File button on the Format tab. A Save As dialog box will prompt you to choose a location and filename to save the new web part configuration. It is important to remember that when you export to a file, you are saving only the configuration information. If the web part is not installed in the new environment, you won’t be able to use the exported web part configuration.

images Note If you were to open a .dwp or .webpart file, you would see that it is just an XML file storing the web part’s configuration. Because it is an XML file, you can modify the configuration in the file if you are careful. Always remember to make changes only to a copy of the original.

EXERCISE 4-5. EXPORTING WEB PARTS

images

Figure 4-37. Selecting the exported web part

Fixing Broken Pages

At times you may need to recover a page after a code change makes it impossible to render, or you might have some orphaned web parts (web parts that have been closed but not deleted) on a page that you need to restore. You can try to open the page in SharePoint Designer in Maintenance mode. To enter Maintenance mode, open the browser and select the Page tab on the Ribbon menu. Then click the Edit Properties button. Once the menu changes, click the Open Web Part Page in Maintenance View link. If you are unable to reach that menu or the page does not render, you can attempt to open the page in Maintenance mode by appending ?Contents=1 to the end of the page URL—for example, http://SharePointDesigner2010/default.aspx?Contents=1.

Summary

This chapter covered how to manage web parts. You learned where you can place web parts and how to create the pages that can hold those web parts. You also learned about exporting and reusing your preconfigured web parts as well as creating web part connections. As you have seen, web parts make it possible to create all sorts of dynamic web sites quickly and with minimal effort.

images

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.37.136