In the previous chapter, you saw how SharePoint lists and libraries are reflected in the Data Source Library task pane. You probably noticed several other sections. Microsoft Office SharePoint Designer 2007 enables you to connect to and manage many different types of information.
All of the formatting and display capabilities of Data Views described in chapter 10 can be used with any data source defined in the Data Source Library, including conditional formatting, Web Part connections, and custom XSL.
Within each section of the Data Source Library, you will see a link to enable you to add a new data source of that type. After filling in the definition forms (except for lists and libraries), an XML file defining the data source will be saved in the /_catalogs/fpdatasources library.
XML definition files are not grouped within the fpdatasources library folder to match the grouping in the Data Source Library task pane. They are all simply stored at the root level.
Each type of data source has slightly different configuration requirements and therefore different forms for filling in the details. Nevertheless, there is certain information that is similar for any data source, and that information is entered on the General tab, as shown in Figure 11-1.
Figure 11-1
To enter or edit any of this information, switch to the General tab (when you create a new data source, the Source tab opens by default). You are not required to enter any information on the General tab; however, if you do not enter a friendly name, an arbitrary generic name such as NewDataSource1 is created when you save the data source for the first time.
Although the forms for adding and modifying a data source are the same, be aware that changes made to a data source after Data Views based on it have been created do not flow through to the existing Web Part. In essence, once created, each Data View retains its own independent instance of the data source definition.
Each data source in the task pane has a menu that provides you with several options. Figure 11-2 shows the menu for the Announcements list.
Figure 11-2
SharePoint Lists and Libraries
SharePoint lists and libraries are automatically added to the Data Source Library task pane when they are created. You do not need to manually create entries for them. In addition, unlike most data source definitions, these automatic entries have direct links to the underlying list or library, and therefore are not normally listed in the fpdatasources folder. You have the option to create new lists or libraries from the appropriate sections. Remember, however, that SharePoint Designer does not offer the capability to add or remove list or library fields directly.
Because the data source is tied directly to the list or library, unlike most data sources, lists and libraries do not show a query editor by default. The Data Source Library does give you a way to limit the available fields or rows when creating Data View Web Parts, though, and that is through the Copy and Modify option in the item's menu. This overrides the normal direct connection to the list, and opens the query editor shown in Figure 11-3.
Figure 11-3
The query editor is normally readily available when defining other types of data sources.
From here you can simplify the list's data display, prefilter results down to a subset, or create XPath calculated fields for direct selection when creating Data View Web Parts. When you click OK, SharePoint Designer saves a copy, and it appears as a new source in the list or library section of the Data Source Library task pane. In addition, unlike its parent list, this entry has an .xml definition file in the fpdatasources library, just like any other data source.
An HTMLEncoded version of the CAML query you define with the query editor is embedded in the XML definition file.
Database Connections
Creating a database connection is a two-stage process. First, clicking the “Connect to a database...” link produces a very simple dialog containing the General tab described previously and a Source tab with a single button (Configure Database Connection). Clicking this launches the second stage—the Database Connection Wizard.
There are several steps to creating a database connection. The first step (see Figure 11-4) defines the type and location of the database, and provides any needed access credentials.
Figure 11-4
If you wish to connect to a database other than Microsoft SQL Server (for example, Oracle or MySQL), you can check the Use custom connection string box and provide an appropriate connection string directly.
Important: |
|---|
|
It is important that both the servers running Windows SharePoint Services and the client running SharePoint Designer have access to the database server for this process to succeed. This includes both network access and appropriate client drivers. Visitors to the site will not need client drivers. They may require appropriate credentials if common credentials or anonymous access to the database is not provided.
|
When you click Next, connection to the database is verified, and you are presented with a form to define the record set you want to use. You can select a table, view, or stored procedure, or indicate that you wish to enter a SQL query directly. If your SharePoint server administrator has enabled update query support, you may also define the statements required for writing information back to your data set. Figure 11-5 shows the Database and Table (etc.) selection page of the Database Connection Wizard.
Figure 11-5
If you select the option to specify custom queries, when you click Finish, this dialog will be followed by a form for building your queries.
After completing the wizard and saving your database connection, viewing the properties displays the Query options panel in the Source tab, allowing you to easily define or fine-tune subsets of your primary data source query.
XML Files
Creating a new XML reference is very straightforward. You can either import an XML file into your SharePoint site, or if the XML file is stored online, simply create a link to it. An online XML file does not need to be within a SharePoint site, but it does need to be accessible via either http or https.
If the server containing the file does not allow anonymous access, you can provide login information on the Login tab of the data source definition, shown in Figure 11-6.
Figure 11-6
The Login tab is the same for most data sources other than databases, the Business Data Catalog, and SharePoint lists and libraries.
Server-Side Scripts
Most server-side scripts, such as traditional .asp, .php, and Cold Fusion (.cfm), are designed to accept parameters from a form page. If the script can return results in XML format, you can create a connection to that script that provides the input parameters it expects, and returns the XML to Windows SharePoint Services. Figure 11-7 shows the Source tab of a server-side script data source.
Figure 11-7
At a minimum, you need to provide the URL of the script. If the script does not require any parameters, you do not need to enter any other information. If you need (or want) to provide extra information for the script, there is further work to do.
HTTP Method
Web forms can be submitted in two ways: HTTP Get and HTTP Post. The method you choose depends on the server-side script. Some scripts are independent of the method, but most require one or the other.
A script that uses the HTTP Get method is easy to recognize because parameters are passed as part of the URL. Such a URL might look like this:
http://www.example.com/inventory/products.asp?CompanyID=25&InStock=true
The parameters in this case are CompanyID and InStock.
When accessing a script that requires the HTTP Post method, the parameters are passed within the HTTP request header itself and are not normally visible to a user. To use this method, you need to find out from the application designer what parameters are expected by the script.
A few, very rare scripts depend on certain parameters to be submitted with each method. SharePoint Designer cannot configure connections for scripts that require parameters from both methods simultaneously.
Data Command
Most of the time, you only want to read and display (that is, Select) information from your external data source, so you simply leave the default Select option chosen. In addition to querying, however, some scripts allow you to insert, update, or delete the underlying data. To implement those functions in your Data View or forms, select the appropriate command from the Data Command dropdown. Each of the functions has its own set of parameters defined.
Parameters
Once you determine the HTTP method and Data Command, you can add any required parameters to the parameter table. In the parameter dialog, you can specify both the name and a default value for each parameter. In addition, you can designate a parameter as run time by checking the box for The value of this parameter can be set via a Web Part connection. Figure 11-8 shows the dialog to add or modify a parameter.
Figure 11-8
XML Web Services
XML Web Services are like an enhancement of server-side scripts, with a major exception—most server-side scripts are meant to be called from other pages within the same application. Web services, on the other hand, are designed specifically to be called by other applications, so there are some key differences between setting up a server-side script data source and setting up an XML Web Service data source. Figure 11-9 shows the Source configuration screen for an XML Web Service.
Figure 11-9
Service Description Location
As you did for the server-side script, you need to provide a URL to access a web service. For a web service, however, the URL you enter here typically will include the specific parameter ?WSDL, which means Web Services Description Language, or Web Service Definition Language. This parameter instructs the web service to return information about how it is used in a standardized XML form. SharePoint Designer then uses that information to provide the options for the remainder of the configuration.
Data Command
Again, as with the server-side script, you configure Select, Insert, Update, and Delete commands independently. Most of the time, you only configure a Select command. If the web service provides operations for the other commands, and you want your Data View Web Part to implement them, simply configure the remaining sections appropriately for each command.
Port
If a web service supports multiple interfaces, the Port option allows you to specify which interface to use. You typically use the first option provided, unless the web service provider gives specific instruction to the contrary.
Operation
Upon connecting to the WSDL file, SharePoint Designer populates the Operation dropdown with the supported functions of the web service. Select the operation you want to perform to implement the current command.
Parameters
After you select an operation, SharePoint Designer populates the Parameters table. This is much simpler than discovering the parameters for a server-side script because you do not have to guess or dig through possibly unobtainable documentation to determine what the functions expect.
Parameters to a web service may be optional or required. Required parameters are indicated by an asterisk (*). As with server-side script parameters, you may predefine a default value for a parameter and also make it configurable at run time (through a Web Part connection, for instance). Unlike server-side script parameters, these values can be complex entities that contain many elements, such as arrays, and have data types that can be enforced. For complex data types, each element can have a default value and/or runtime source specified.
You cannot add parameters to or remove parameters from a web service data source, because they are predefined in the WSDL. For optional parameters, just leave the configuration elements blank if you are not going to use them.
Business Data Catalog
Unlike other intrinsic SharePoint components, Business Data Catalog objects are not automatically included in the Data Source Library. When you open a SharePoint site, you need to add them individually to the available data sources. Figure 11-10 shows the Business Data Catalog data source configuration screen.
Figure 11-10
Each Business Data Catalog data source represents one entity type from one application. Business Data Catalog applications and entities are defined farm - wide, and invoked where needed. Most parameters of a Business Data Catalog list are set centrally, but you can apply basic filters to your data source to avoid returning the potentially millions of records in an enterprise application with a single query. In addition, when creating a Data View, you still have the option of selecting specific data columns and applying additional filters.
SharePoint Designer also allows you to connect to Data Source Libraries in other SharePoint sites and to leverage some or all of the data sources defined therein. The exact sources available through the connection will depend on the relationship (if any) between the current site and the site of the library to which you are connecting.
To connect to another site, open the Data Source Library task bar, and click the Connect To Another Library link at the bottom of that pane. This opens the Manage Library dialog, which lists the external libraries that are currently connected (see Figure 11-11).
Figure 11-11
Click the Add button to enter a descriptive name and the URL of the library you want to add. Click the Browse button to navigate to a particular SharePoint site, and click the Open button in the browse dialog to insert the selected site into the Location field. Alternatively, you can manually enter a URL in the field. In either case, once you have selected the site, click OK to establish the connection.
If the site you have selected is not available, or does not have a sharable Data Source Library, you will get an error message, and the library will not be added to the list.
Note: |
|---|
|
Once you have opened another site’s Data Source Library, you are not working on a local copy of the data source. Any changes you make in the connected library are reflected back to the original source! Verify which portion of the Data Source Library you are working with before making changes.
|
Sites in the Same Site Collection
Connect to another site in the same site collection, and you have access to all of the data sources defined within the site, including the site's lists and libraries, and any external data sources. If you are using Office SharePoint Server, you also have access to the Business Data Catalog sources defined in the target site. Linked data sources are available, but may not function as expected if any of the constituent data sources require permissions not possessed by users of the connecting site.
Sites in a Different Site Collection
When you connect to sites in a different site collection—whether on the same server or on a different SharePoint server—you only get access to the user-defined data sources and XML files. You cannot access the target site’s lists and libraries. If the target site is a SharePoint Server site, you do not have direct access to any Business Data Catalog entries.
All linked data sources from the selected Data Source Library will be listed. Linked data sources made up of elements that can cross site collections will function normally. If a linked data source is composed with any elements that are not available as described above, however, that data source will not function.
In the previous chapter, you saw how you could use Windows SharePoint Services and SharePoint Designer to relate Web Parts through Web Part connections. Another way to blend the display of heterogeneous data is through linked data sources. A linked data source enables you to define a relationship between two or more existing data sources and present them in a single Data View.
To select elements for a linked data source, click the Create A New Linked Source link, or select Edit from the data source context menu. The Data Source Properties dialog shown in Figure 11-12 appears. It is initially unpopulated.
Figure 11-12
Click the Configure Linked Source button to launch the Link Data Source Wizard. The first page, shown in Figure 11-13, lists all of the data sources in each of the Data Source Libraries you currently have connected.
Figure 11-13
Select and order the data sources you want, and then click Next. Select the type of link you want to create: merge or join.
A merged data source (see the left side of the Link Data Source Wizard example in Figure 11-14) is useful if the information in the component sources can be considered components in a single list. For example, you may want to roll up list information from multiple sites in your collection for a single view on the home page.
Figure 11-14
A joined data source (see the right side of the wizard example in Figure 11-14) is most useful when there is a hierarchical or one-to-many relationship between the elements in the component data sources. A SharePoint list of client contacts, joined to the Orders table of a financial system (connected through the Business Data Catalog), for instance, might make a very useful linked data source.
Note: |
|---|
|
When creating a linked data source, ensure that your intended users have permission to at least read all of the constituent data sources. Otherwise, any Data View Web Parts using that source will display only an error message for users who do not have such permission, even if they have permission to read some of the data.
|