P A R T   II

images

Advanced Site Customization

C H A P T E R  5

Displaying Data

SharePoint Server 2010 is a platform that can be used to integrate data from many sources. Some of these sources reside within SharePoint itself, such as lists and libraries. Others are external data sources. These include Relational Database Management Systems (RDBMSs) such as Microsoft SQL Server or database products from other vendors such as Oracle and IBM. Data can also be retrieved from web services, Really Simple Syndication (RSS) and Representational State Transfer (REST) feeds, or from XML files. SharePoint's Business Connectivity Services (BCS) system is also a versatile way to access data.

This chapter focuses on the presentation of data. SharePoint Designer has some excellent tools for customizing the presentation of data—including capabilities to read, delete, and update data residing in various types of data sources. Because this chapter focuses on presentation, you will work only with data stored in SharePoint lists and libraries. For details about using other types of data sources, see Chapter 10.

You will learn about the following topics in this chapter:

  • Accessing data within a SharePoint Page
  • Understanding data sources in SharePoint Designer
  • Creating site pages containing data list and form web parts
  • Customizing the look and feel of data web parts
  • Passing parameters to and between data web parts
  • Knowing which web parts to use in different situations

images Note The following software is required:

  • SharePoint Server 2010 (Enterprise edition recommended)
  • SQL Server 2008 (R1 or R2)
  • SharePoint Designer 2010

Understanding Data Sources and Data Views

There are three primary considerations when displaying or updating data: the data itself, how the data is accessed, and how the data is presented. SharePoint provides a common platform for presenting data in a web-based format. SharePoint Designer leverages that platform to allow the designer to customize the retrieval and presentation of data from a variety of sources.

As noted earlier, in this chapter you will focus on data that is stored within SharePoint in the form of lists and libraries. As you saw in Chapter 2, lists in SharePoint can be thought of as tables of information. Each item in the list is a row in the table. Each value or attribute associated with the item is a column in the table. When accessing data from lists, it is helpful to think of lists as tables because that is usually how the presentation is formatted; Figure 5-1 shows an example. A SharePoint library is just a specific type of list that is designed to store a document along with each item.

images

Figure 5-1. A task list as a table of information

The task of accessing data in SharePoint by using SharePoint Designer is divided into two components: a data source and a data view (or form). Data sources provide a description of where the information being displayed will come from. The data source also defines the form of the data, including what values and data types are associated with each field. A data view, or form, is a web part that can be placed on a SharePoint page, bound to a data source, and customized to render the data in precisely the way desired.

In the following sections, you will explore the types of data sources that are available. You will then move on to a description of the various web parts that are available for presenting this data and will learn how to customize their appearance. Finally, you will walk through some common scenarios for creating and customizing the presentation of data by using SharePoint Designer.

Working with Data Sources

As stated in the preceding section, a data source in SharePoint is an object that defines the parameters needed to connect to a particular set of data. For example, a data set might point to a list within SharePoint or to a table in an RDBMSS such as MS SQL Server or Oracle. In addition to retrieving data, data sources can also be configured to insert, update, or delete information from the underlying data source, if the user has the necessary security privileges.

A typical SharePoint site contains some data sources by default, and more can be added through SharePoint Designer. If you open your web site in SharePoint Designer and click Data Sources within the Navigation pane, the Data Sources Gallery displays. This window, shown in Figure 5-2, contains a catalog of all data sources available within the current site.

images

Figure 5-2. The Data Sources Gallery

Lists and Libraries

Data sources are created in one of two ways: automatically or manually. SharePoint Designer automatically exposes data sources associated with internal and external lists and with libraries that exist within the site. These data sources are configured to return all of the information from those sources and, where permitted, to support updates to items in those lists.

In most cases, it is not necessary to create new data sources for lists and libraries, but it can be done if necessary. The data source automatically created for a list cannot be altered except by changing the underlying list. However, to create a customized view of the data in a list, a new data source can be created and configured:

  1. Open the Data Sources Gallery by clicking Data Sources in the Navigation pane.
  2. Select the list you wish to use in the gallery page and then click Copy and Modify from the Actions group on the Data Sources tab on the menu, as shown in Figure 5-3.
    images

    Figure 5-3. The Copy and Modify action

  3. The Data Source Properties dialog box appears (see Figure 5-4). Using the options on the Source tab, you can select the fields to be made available through the data source, the sort order for the data, and any filters that may be needed to limit the items returned. Because lists and libraries may contain folders, there is also an option to select the scope of items to be returned. Leaving these options alone will create a new data source exactly like the old one.
    images

    Figure 5-4. Data Source Properties dialog box

  4. Click the General tab. Set the name and description for the new data source and then click OK to create it.

The new data source can now be used like any of the automatically created data sources except that it can be altered and deleted if necessary.

images Note This technique for copying and modifying a data source is not unique to list data sources. Any data source can be copied and altered in the same way.

When you create a new data source, it appears in the Data Source Gallery. The gallery is just a conceptual container within SharePoint Designer, not a physical directory within the site. The data source you created was written as XML to a file in the web site. To work with this file directly, you can locate it in the All Files Gallery:

  1. Click All Files in the Navigation pane. This displays a Gallery page that looks like Windows Explorer, as shown in Figure 5-5. These are the files and folders that are stored within the site.
    images

    Figure 5-5. The All Files Gallery page

  2. Click the _catalogs and then fpdatasources folders.
images

Figure 5-6. The fpdatasources folder

This folder contains all of the manually created data sources within the site. These are stored as XML files. These files can be exported to other locations or managed like any other file within SharePoint Designer. Any changes made to these files are automatically reflected in the Data Source Gallery.

images Caution The XML in these data source files can be complex and difficult to understand. Use great care when attempting to edit these by hand. Where possible, use the built-in editors that are launched by clicking the data source in the Data Source Gallery.

Linked Data Sources

A linked data source allows the designer to combine the data from multiple data sources into a single set of data. The data sources being linked need not be of the same type. For example, data from a SharePoint list could be linked with relational data or web service data. This opens up many possibilities for using SharePoint Designer to present consolidated views of information from throughout the organization.

A linked data source can combine the information from a pair of data sources in one of two ways: merging or joining.

Merging data sources is like shuffling a deck of cards. The records of the two data sources are simply combined into a single list. The combined list can be sorted and filtered as though all of the data came from a single source. Figure 5-7 illustrates merging data.

images

Figure 5-7. Linking data sets by merging data

The other option for linking data sources is to perform a join operation. Joining data involves creating new records by combining the fields of related records in the two data sources. Instead of having a list containing all of the entries of both lists, as in merging data, a joined data set will contain one entry for each combination of related records. This allows you to combine different types of information from different locations to produce new insights into the data. Figure 5-8 illustrates joining data.

images

Figure 5-8. Linking data sets by—joining data

External Lists

An external list is a special type of SharePoint list that stores its data outside of SharePoint Server. This data is accessed by using the BCS subsystem within the SharePoint server. To use BCS, you create an external content type that serves the function of defining the data that is being stored externally. An external list is then created by using the external type to give access to the data. An external list is just another list when used as a data source. It may or may not support writing changes back to the underlying data source, but can otherwise be used like any other list.

images Note For additional details on using external lists and the other data source types described throughout this section, see Chapter 10.

Database Connections

RDBMSs are among the most common and versatile data storage systems used by most companies. The data stored in these databases is often used by various applications throughout the organization. SharePoint Designer allows this data to be queried and modified through data forms and views presented within a SharePoint site.

SharePoint Designer database connections can connect to most modern relational systems, including those supporting the Object Linking and Embedding, Database (OLE DB) and Open Database Connectivity (ODBC) protocols. For additional functionality, performance, and ease of use, custom interfaces are provided for Microsoft SQL Server and Oracle databases.

When accessing data through a database connection, three methods are available for providing credentials. The simplest means is to provide a user ID and password with the required access privileges as part of the data source. You can also provide a complete, custom connection string as part of the data source's configuration. The problem with both of these options is that there is no way for the back-end database to enforce user-specific permissions because all access is made by using a single account. SharePoint Designer provides a further option to solve this problem. Using SharePoint's Secure Store Service (SSS), a database connection can be configured to access the back-end database using credentials that are specific to the user accessing the data. For more information on SSS, see the TechNet article at http://technet.microsoft.com/en-us/library/ee806889.aspx.

Beyond retrieving data, a database connection can also be configured to support the full range of create, read, update, and delete (CRUD) operations. The user can supply custom SQL or stored procedures to support inserts, updates, and deletes in addition to the default SELECT query.

images

Figure 5-9. Edit Custom SQL Commands dialog box

XML File Connections

An XML file connection allows XML-formatted data to be presented on a SharePoint site. The XML file may be stored locally within the site or accessed from another site by using a URL. When an XML file is added to the local site, it is automatically listed in the Data Sources Gallery. External XML files must be added manually.

When accessing local XML files, SharePoint enforces its normal access controls. When accessing remote XML files, it may be necessary to provide login credentials. This can be done either statically, by providing a fixed username and password, or dynamically, by using Windows Authentication or SSS.

XML files used as data sources are not required to have an associated Document Type Definition (DTD) or XSD schema definition. Therefore, these files can contain any valid XML markup.

Web Service Connections

A web service is a location on the network where a program can make a request and receive data in response. The interaction is similar to a web page, except that there is no user or web browser involved. A program makes a request from the web server behind the scenes. Web services are typically based on the SOAP protocol. SOAP, when it was originally created by Microsoft, stood for Simple Object Access Protocol, but that name is no longer used. SOAP is now a widely accepted Internet standard for web services. SOAP-based services exchange XML requests and responses over a network. SharePoint Designer web service connections allow this data to be presented within a site.

Secure web services may require the caller to provide login credentials. This can be done either statically, by providing a fixed username and password, or dynamically, by using Windows Authentication or SSS.

A web service may require parameters that can be passed into the data source by using a web part connection. This allows the caller to pass information as needed to access the data desired. The request and response required by the web service are defined in its Web Services Description Language (WSDL) file. SharePoint Designer uses this file to properly format calls into a web service. The result is a response XML document that can then be formatted by using SharePoint Designer's data view web parts.

images Note If you are running your site by using MS SharePoint Foundation instead of SharePoint Server, you will need to update the web.config file for your site to allow it to use web services. This feature is turned on by default only when using the server product. For details, see http://office.microsoft.com/en-us/sharepoint-designer-help/add-a-soap-service-as-a-data-source-HA010355752.aspx.

Server-Side Script Connections

A server-side script connection is very similar to a web service connection in many ways. A server-side script is a program that runs on a web server and is designed to provide a data feed in XML format. The most obvious example of this type of script is a web log, or blog. When viewed in a web browser, a blog appears to be like any other web page, but behind the scenes, blogs provide a series of XML documents that are consumed by some other application.

The terminology gets somewhat confused because Microsoft also sometimes refers to these connections as REST service connections. REST is an architectural style for exposing web services in a simplified way. REST is only one type of server-side interface supported by SharePoint Designer. RSS feeds are also supported. RSS feeds are the traditional interface for blogs. However, many blogs also use REST and Atom Syndication feeds. These are all supported by SharePoint Designer.

In reality, a server-side script is just a program that accepts parameters and returns XML over a standard HTTP connection. Therefore, a basic service can be written by using almost any server-side technology such as ASPX, CGI, PHP, and so on.

When configuring a server-side script, it is important to have the following information beforehand:

  • What is the URL of the script?
  • What parameters are necessary?
  • Does the service use the HTTP GET or POST protocol?

Unlike a SOAP web service, these services do not provide a WSDL file that can guide SharePoint Designer in preparing the correct parameters for the service.

images Note If you are running your site by using MS SharePoint Foundation instead of SharePoint Server, you will need to update the web.config file for your site to allow it to use server-side scripts as a data source. This feature is turned on by default only when using the server product. For details, see http://office.microsoft.com/en-us/sharepoint-designer-help/add-a-soap-service-as-a-data-source-HA010355752.aspx.

Using Data View Web Parts

SharePoint Designer presents data from a data source by using one of several data view web parts. There are several of these web parts, and each is tailored for use in certain situations. They all share certain attributes that make them easier to configure and customize.

The data web parts can be split into two classifications: list views and form views. List views display information as a table of information, as shown in Figure 5-10.

images

Figure 5-10. List view web part

Form views are most often used to display the details of a record or allow it to be inserted or updated, as shown in Figure 5-11.

images

Figure 5-11. Form view web part

images Note Unfortunately, the names of the data web parts have gotten very confusing over time. Some of the web parts can be used for more than one thing, leading to names that contain seemingly random combinations of the words List, View, Data, and Form. SharePoint 2010 introduced a new set of web parts with XSLT in the name. This has only added to the confusion, because these are not the only web parts that support XSLT formatting. A catalog of these web parts is presented later in this chapter. Be careful to note which web parts are used with which data sources and in which situations. Try not to get hung up on the names because they can be misleading. This is why they are frequently abbreviated with names such as XLV and DFWP that have little meaning on their own.

When working with data web parts, the Data Source Details task pane provides a view of the data that is being presented, as shown in Figure 5-12. The Data Source Details pane appears to the right of the main window automatically when a data web part is present on the page. If it does not appear when needed, it can be activated manually by selecting the View tab on the menu and then selecting the Data Source Details item from the Task Panes drop-down menu in the Workspace group.

images

Figure 5-12. Data Source Details task pane

Regardless of the type of data source being used, the data is always described in this task pane as an XML document. XML provides a standard form for describing the data being presented. The Data Source Details pane can be used to view data values, create additional related web parts, and add additional fields to an existing data web part by dragging and dropping fields onto the Page Editor.

The data view web parts can provide highly customized presentations because of their use of XML. The data values from the data source are passed to the web parts as an XML document. The web part then uses XSL Transformations (XSLT) to convert the XML into the HTML that is sent to the user's web browser.

In Figure 5-13, some HTML markup has been added to the XSLT associated with a DataFormWebPart. In the Page Editor's Split view, it is easy to see the result of your modifications in near real-time. Highlighting objects in one view panel causes them to be highlighted in the other. XSLT formatting allows for very tight control of the exact rendering of information in the data web parts, without sacrificing the functionality of the underlying data source.

images

Figure 5-13. XSLT formatting in the Page Editor (Split view)

images Note For those wanting to learn more about formatting data by using advanced XSLT markup, take a look at Jeni Tennison's Beginning XSLT 2.0: From Novice to Professional (Apress, 2005).

Data web parts are also designed to work together by passing parameters using web part connections. For example, a list of items can send an item's ID to a form view when an item is selected. These connections can also be used between pages when necessary.

List View Web Parts

List view web parts are primarily used to display lists of information from a data source. There are only two purely list-oriented web parts: the ListViewWebPart and the XsltListViewWebPart. Table 5-1 details the two list view web parts.

images

Data Form Web Parts

Form-oriented web parts are primarily for displaying detailed data about an item. These forms can also be used to create and update items in some cases. Table 5-2 lists these data form web parts.

images

images

Creating Data Pages in SharePoint Designer

Now that you are familiar with the data access components available through SharePoint Designer, let's try putting the pieces together.

In the following exercises, you will create a set of related lists within SharePoint. These lists will provide the information for your data pages. You will customize the views and forms that are automatically generated by SharePoint. You will then create two new web pages by using SharePoint Designer's data web parts. The first page will be a simple listing of orders that will allow you to subtotal your orders geographically. The second page will provide a means of filtering data, passing parameters, and entering data by using the data web parts.

EXERCISE 5-1. CREATE DATA LISTS

images

Figure 5-21. Order Lines list definition (complete)

Now that the lists have been created, you need to create some sample data in the lists to work with. You can do this by using the data entry forms available in SharePoint, through the Datasheet view (if available in your configuration) or through the SharePoint Workspace client application. The data you will use in the rest of this chapter is shown in Table 5-3, Table 5-4, and Table 5-5 and can be downloaded from this book's web site.

images

images

images

EXERCISE 5-2. CUSTOMIZE GENERATED VIEWS AND FORMS

EXERCISE 5-3. CREATE A CUSTOMIZED REPORT PAGE

images

Figure 5-41. Orders report page

With just a few clicks, you have created a custom report based on the order data within these SharePoint lists. With further formatting and XSLT changes, the possible variations of this type of report are virtually limitless.

EXERCISE 5-4. CONNECT AND PARAMETERIZE DATA WEB PARTS

Summary

In this chapter, you have

  • Introduced Data Access using SharePoint Designer
  • Explored the Data Sources Available in SharePoint Designer
  • Examined Which Web Parts to use in Different Situations
  • Created and Customized Data Pages Using Data Web Parts
  • Enabled the Passing of Parameters Between Data Web Parts
images

Figure 5-54. Road map to accessing data with SharePoint Designer

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

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