Web Parts Basics


In this section, you learn the basics of working with Web Parts - operations common to most Web Parts. As mentioned earlier, you add Web Parts, stored in a site’s Web Part gallery, to a Web Part page. Users with appropriate permissions can access this gallery by entering the Edit mode for a Web Part page where they can add Web Parts to a Web Part page in one of the clearly marked Web Part zones. You can enter Edit mode by selecting Edit Page from the Site Actions menu. Figure 7-4 shows an example of a page in Edit mode.

image from book
Figure 7-4

From this mode, you can do the following:

  • Add Web Parts to a Web Part zone:   Web Parts can be added to the page by clicking an Add a Web Part button available at the top of each Web Part zone. Doing so opens a Web Part selection window displaying a categorized listing of Web Parts.

  • Drag Web Parts from zone to zone:   Web Parts can be moved from one Web Part zone to another by simply selecting the title bar of a Web Part and dragging it to the desired zone.

  • Change properties of a Web Part:   When a Web Part page is in Edit mode, an Edit button appears on the right-hand side of each Web Part title bar. By selecting this button, the Web Parts property pane appears. From this pane, you can make changes to the configuration, appearance, or behavior of the Web Part. You may also change the location of the Web Part using this pane.

  • Export a Web Part:   You can export some Web Parts from a page and reuse and import them on another page. When a Web Part is exported, all settings for the Web Part are retained and saved in a file that can later be imported to another SharePoint page or site.

    Tip 

    To learn what the different SharePoint Web Parts are and how to use them, see the next section, “Using the Various SharePoint Web Parts.”

In addition, when adding a Web Part to a zone from the Web Part selection window, you have the option of entering the Advanced Web Part gallery, shown in Figure 7-5. From this gallery, you can do the following:

  • Browse for Web Parts:   You can browse the available galleries of the site and server in an intuitive manner. In Figure 7-5, you can see three galleries:

    • Closed Web Parts include any Web Parts previously added to the page but that a user with the appropriate permissions has closed. When a Web Part is closed, it no longer appears on the page, but only in this gallery.

    • Site Gallery Web Parts are Web Parts that SharePoint offers as well as any Web Parts unique to the site, such as list- and library-related Web Parts. See the next section, “Using the Various SharePoint Web Parts” for more information.

    • Server Gallery Web Parts are those custom Web Parts installed on the server that have either been developed or purchased separately to meet a specific need of the organization.

  • Import Web Parts to a page:   You can import Web Parts to a page from another location, such as your desktop or a network share. To import a Web Part, you must select Import from the menu at the top of the tool pane, as shown later in this chapter in Figure 7-15.

  • Search for Web Parts:   As a Web Part gallery grows, it becomes tedious to browse through the Web Part listings. Therefore, SharePoint has a search function in the Advanced Web Part tool pane specifically for searching for Web Parts across all galleries. This is helpful if you are unsure in which gallery a Web Part is available.

image from book
Figure 7-5

The next few Try It Outs focus on some of the features just discussed so you can understand how each works and how you can manage activities related to your Web Parts. The first Try It Out has you working with the Content Editor Web Part to add and format content. You then learn, in the second Try It Out, how to tailor to your Web Part to meet your corporate culture; each Web Part has properties and attributes that you can use to modify a Web Part’s title bar, border, height, and width. In the third Try It Out, you use the Edit mode to drag Web Parts above or below other Web Parts in the same zone, or to a completely different zone.

No matter what the technology, it’s always best to make things reusable. SharePoint helps you recycle Web Parts by allowing you to export them as single portable files with a .DWP or .WEBPART extension. You learn how to export in the fourth Try It Out in this section. You can then use the fifth and final Try It Out to import a Web Part to another site.

Try It Out-Add a Web Part to a Page

image from book

In this example, you add the Content Editor Web Part to the backgroundinfo.aspx page you created in the “Create a Web Part Page” Try It Out. This Web Part allows you to add free-form text related to your company. Because you haven’t added any content, when you first place the Web Part to the Web Part zone, you’ll see instructions on configuring the Web Part. Your next action is to launch the Web Part Tool Pane so you can change the Web Part’s appearance, layout, and content. The Content Editor Web Part has buttons that allow you to edit content either in a rich-text editor or a source editor. This Try It Out demonstrates both options.

  1. From the home page of your team site, select the Shared Documents library from the Quick Launch navigation bar.

  2. Select the backgroundinfo.aspx page you created in the previous Try It Out.

  3. Select Site Actions image from book Edit Page. The Web Part Zones on the page should now be clearly visible, as shown in Figure 7-6.

    image from book
    Figure 7-6

  4. Select the Add a Web Part link from the Left Column Web Part zone. The Add Web Parts – Webpage Dialog window appears, as shown in Figure 7-7.

    image from book
    Figure 7-7

  5. Locate the Content Editor Web Part from the Miscellaneous group.

  6. Click the Add button. Your Web Part becomes visible on the page.

  7. Click the Open the Tool Pane link. The Web Part Tool Pane appears on the right side of the window.

  8. Click the HTML button from the pane. A HTML editor appears as shown in Figure 7-8.

    image from book
    Figure 7-8

  9. Enter the following text into the window.

    Important 

    Company Background

    Our company started in the year 1990 as a small player in a large market. Through excellent customer service and a dedicated and innovative staff, we have grown to become the market leader in bamboo ski repair.

    From the beginning, we have focused on differentiating ourselves from the competitors by building long-term relationships with our customers and offering no-charge post sales support and ski repair.

  10. Select the words company background and click the Bold button from the Editor toolbar.

  11. Click the OK button.

  12. Click the Source Editor button from the Content Editor Web Part pane.

  13. Enter the following code below the last line of the content in the editor:

    Important 

    Committed to Service

    If, for any reason, a customer is not satisfied with their ski purchase, we will refund their money 100 percent, no questions asked.

  14. Click the Save button.

  15. Click the Apply and OK buttons at the bottom of the Web Part tool pane.

How It Works

As this example shows, you can add a content editor to a page to allow users to add content. Most business users will prefer the rich-text editor because it has buttons similar to the formatting buttons you find in Word. Users familiar with HTML may prefer the source editor.

image from book

Try It Out-Modify the Appearance of a Web Part

image from book

Every Web Part has a set of customizable features such as Appearance, which you can modify via the Web Part Properties tool pane. By selecting the Modify option from a contextual menu, you can change the Web Part’s title, height and width, and chrome. Chrome refers to the appearance of the interface, so changing the chrome type will alter things like the Web Part’s border and title bar.

  1. Open the backgroundinfo.aspx page from the previous Try It Out.

  2. Select the down arrow on the right-hand side of the Content Editor Web Part title bar to open the contextual menu, shown in Figure 7-9.

    image from book
    Figure 7-9

  3. From the list of available options, select Modify Shared Web Part.

  4. From the Web Part tool pane, locate and expand the appearance section, as shown in Figure 7-10.

    image from book
    Figure 7-10

  5. In the Title field, type a title for the Web Part. For this example, type Corporate History.

  6. Leave the height, width, and chrome state at the default settings.

  7. For Chrome Type, select Title and Border.

  8. Click the OK button. You’ll notice that your Web Part has a border and title.

image from book

Try It Out-Move a Web Part to a New Web Part Zone

image from book

As discussed earlier, Web Parts have zones, into and out of which you can move Web Parts to alter the look of your page. To do this, you enter the Edit mode, and drag the Web Part above or below Web Parts in the same zone or to a different zone. This demonstrates a Web Part’s flexibility; in the past, you had to make significant code updates to make simple layout changes to a page, but by using Web Parts, you can move content modules anywhere on the page by just a few simple actions.

  1. Select Site Actions image from book Edit Page. Your page is now in Edit mode, as shown in Figure 7-11.

    image from book
    Figure 7-11

  2. Click the title bar of a Web Part and then drag and drop it from one zone to another or within the same zone, just as long as the Web Part stays in a zone. You cannot drag a Web Part to an area of the page that doesn’t have a Web Part zone.

image from book

Try It Out-Export a Web Part from a Page

image from book

You may find it useful to reuse an already configured Web Part on another site, particularly when the Web Part contains specialized content and customizations that would be difficult to recreate. SharePoint allows you to export Web Parts as single portable file (.DWP or .WEBPART), which you can then easily move to another site. With this feature, SharePoint prompts you to name and save the file you want to export to a location on your hard drive.

  1. Select Site Actions image from book Edit Page.

  2. Locate the Web Part you want to export. In this case, you use the Content Editor Web Part you used in the last Try it Out, which is called Corporate History.

  3. Click the Edit button on the toolbar to make the contextual menu appear.

  4. From the contextual menu, select Export as shown in Figure 7-12.

    image from book
    Figure 7-12

  5. Click Save. The Save As window appears, as shown in Figure 7-13. You are prompted to name and save your Web Part. Save the Web Part with the name Corporate_History and place it on your desktop. You should save this with a .DWP extension.

    image from book
    Figure 7-13

How It Works

Some other more complex Web Parts may be with a .WEBPART extension, instead of the .DWP in this exercise, but the purpose is the same. SharePoint automatically determines which format should be used. You can later import this file to a different site using the steps in the next Try It Out.

image from book

Try It Out-Import a Web Part to a Page

image from book

Once you export a Web Part, you can import it to any site you want using the Import command in Edit mode. This command lets you browse through the exported Web Part so you can import them into your Sites Web Part gallery, which you can view in the Web Part tool pane. From there, it’s a simple matter of dragging the Web Part to your page.

In the case of the Content Editor Web Part, you could import the .DWP file to any SharePoint server regardless of location because no references existed to data sources or special assemblies. When working with Web Parts that connect or display data from specific locations, it may be necessary to ensure that the data is accessible from the new location.

  1. Select Site Actions image from book Create. You are redirected to the SharePoint creation page.

  2. Select Sites and Workspaces from the Web Pages group.

  3. Enter a title for the site. For this example, use Corporate Information.

  4. Enter a URL name for the Web Part and select a blank site template. For this example, enter corpinfo for the URL name.

  5. Click the Create button. Your new page is created, and you are redirected to it.

  6. Select Site Actions image from book Edit Page to enter Edit mode for your page.

  7. Select Add a Web Part from any of the Web Part zones. The Add Web Parts – Webpage Dialog appears, as shown in Figure 7-14.

    image from book
    Figure 7-14

  8. From the bottom right of the dialog window now exposed, select Advanced Web Part Gallery and Options. The Add Web Parts tool pane should now be available at the far right of your screen, as shown in Figure 7-15.

    image from book
    Figure 7-15

  9. From the top of the tool pane, select Browse.

  10. A menu appears displaying options for Import and Search; select Import. The pane changes to show an Import section with a Browse button, as shown in Figure 7-16.

  11. image from book
    Figure 7-16

    Select the Browse button. The Choose File window, also shown in Figure 7-16, appears allowing you to locate the Web Part you want to import.

  12. Browse to your desktop and locate the Corporate History.DWP file you exported in the previous Try It Out. When you have the file selected, click the Open button in the Choose File window to complete the operation.

  13. Click the Upload button on the pane. You see a list of imported Web Parts. You are now free to drag these into a Web Part zone.

image from book




Beginning SharePoint 2007. Building Team Solutions with MOSS 2007
Beginning SharePoint 2007: Building Team Solutions with MOSS 2007 (Programmer to Programmer)
ISBN: 0470124490
EAN: 2147483647
Year: 2007
Pages: 131

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