6.3. Using the Find and Replace Features

SharePoint Designer offers an advanced Find and Replace tool that allows you to find and replace content and code in the Design and Code views. This feature provides for searching in a Web page, a set of Web pages, or all across a Web site open in SharePoint Designer. You can match content to be searched by using expressions created with the regular expression syntax. Also, you can create rules for specifying search criteria to match HTML tags and then choose to replace a tag, an attribute within a tag, or the inner content of a tag.

The user interface for Find and Replace is composed of the Find and Replace dialog box and the Find 1 and Find 2 task panes.

6.3.1. Working with the Find, Replace, and HTML Tags tabs

You can access the Find and Replace dialog box, as shown in Figure 6.7, by choosing Edit Find or Edit Replace. To begin with, you can enable the Find 1 and Find 2 menus by using the Task Panes menu. A Play button on both these panes also takes you to the Find and Replace dialog box. The Find 1 and Find 2 task panes provide for running and comparing two search operations at the same time.

The Replace functionality of SharePoint Designer is an irreversible operation. You can't undo the replacement once it occurs. SharePoint Designer warns about this before it runs the replacement operation on a Web site.


Figure 6.7. The Find and Replace dialog box

The Find and Replace dialog box exposes its features using three tabs: Find, Replace, and HTML Tags. All three tabs have a Search Options section that allows you to choose from a set of options to define the scope and direction and set other settings.

6.3.1.1. Find tab

The Find tab allows you to specify the text you want to search. You can also choose to create search queries by using HTML rules and regular expressions, which are discussed later in this chapter. To find some text or code, simply type it in the Find what text box and then click Find All. The Find task pane shows the list of Web pages where your search is successful. Also, the Matched Text column highlights in red the text you typed in the Find what text box.

6.3.1.2. Replace tab

The Replace tab adds the interface to the Find tab for specifying the replacement text and options. Considering that replacement is irreversible, it's recommended that you choose to find first to understand the results retrieved and then run the replacement later. You need to specify the replacement text in the Replace with text box and then click Replace to replace the first occurrence of the text or Replace All to replace all occurrences.

6.3.1.3. HTML Tags tab

The HTML Tags tab allows you to specify a Find HTML tag and then choose a replacement action to define what needs to be replaced or changed in the tag. Choose the HTML tag you need to find by using the Find tag dropdown menu and then choose a replace action by using the Replace action dropdown menu. The Replace action dropdown menu has these options:

  • None: Only finds the tag and doesn't perform any replace action

  • Replace tag and contents: Shows a With text field where you can specify the replacement text that replaces the selected tag and its contents

  • Replace contents only: Allows you to specify the replacement text that replaces only the contents of the tag

  • Add after start tag: Allows you to specify the replacement text that's added after the start of the selected tag

  • Add after end tag: Allows you to specify the replacement text that's added after the end of the selected tag

  • Add before start tag: Allows you to specify the replacement text that's added before the start of the selected tag

  • Add before end tag: Allows you to specify the replacement text that's added before the end of the selected tag

  • Remove tag and contents: Removes the selected tag and contents

  • Remove tag: Removes the tag only

  • Change tag: Provides a To dropdown menu that allows you to choose a replacement tag for the selected tag

  • Set attribute value: Shows an Attribute dropdown menu that allows you to choose the selected HTML tag's attribute and set a value for it

  • Remove attribute: Allows you to choose an attribute for the tag that needs to be removed

Most of the settings in the Search options section of the dialog box are common across all tabs:

  • Find where: Allows you set the search scope. You can choose to search in the current page, in pages selected in the Folder List task pane, in pages that are open, or all pages.

  • Display results in: Allows you to choose the Find task pane where the results of the search are shown

  • Direction: When searching in a page, you can choose the direction of the search.

  • Advanced: Provides check boxes that allow you to set if the search should match the text case, find the whole word only, ignore white space differences, use regular expressions, or find text in a source code

Besides this, the Search options section also provides you with two buttons (placed in the bottom right) that allow you to open an existing query or save the query you create in the Find and Replace dialog box for later use.

NOTE

SharePoint Designer saves the query you create in the Find and Replace dialog box by using an XML format in an FPQ file.

6.3.2. Exploiting the HTML rules

The Find and Replace dialog box provides a cool feature to create matching criteria for your search for HTML tags inside the Web pages. All three tabs in the Find and Replace dialog box have an HTML Rules button. You can click this button to create HTML rules that help you drastically isolate your search. For example, you can find all <a> tags inside the Web site pages that have the target attribute value set to blank and then change the attribute to _self in a single operation.

To create a new rule, follow these steps:

  1. In the HTML Tags tab in the Find and Replace dialog box, choose the <a> tag from the Find Tag dropdown menu.

  2. Click the HTML Rules button. The HTML Rules dialog box, as shown in Figure 6.8, opens.

  3. Click New Rule to enable the New Rule dropdown menu at the bottom of the dialog box.

  4. Choose the With Attribute menu option in the New Rule dropdown menu to enable another set of dropdown menus in the dialog box.

  5. In the [any attribute] dropdown menu, choose the target attribute. Keep the Equals option selected in the next dropdown menu.

  6. In the [any value] dropdown menu, choose _blank.

  7. Click OK.

Figure 6.8. The HTML Rules dialog box

You just created an HTML rule that allows you to find all <a> tags that have the target attribute set to _blank. You can now use the Find and Replace dialog box to specify the replace actions.

6.3.3. Using regular expressions

Regular Expressions is a standard mechanism used by a lot of programs to help identify text strings in large amounts of text based on patterns. In simple terms, a regular expression is a format that describes a pattern of characters in text. For example, the regular expression ca. matches all three-letter words that have ca as prefix, such as cat, can, cap, etc.

The Find and Replace dialog box allows you to use these regular expressions to search for text or text patterns in Web pages and replace them with the needed text. If you click the right-pointing arrow next to the Find what text box, a menu appears showing you a number of commonly used regular expressions, as shown in Figure 6.9.

NOTE

Regular Expressions is a complex but intuitive way to perform searches across Web content by using SharePoint Designer. You can combine the characters displayed in Figure 6.8 to make an advanced expression for comparison. For example, the [A-Za-z0-9] regular expression matches all alphanumeric characters.

Figure 6.9. The Regular Expressions menu in the Find and Replace dialog box

6.3.4. Using incremental searches

Incremental Search is another cool feature especially useful in the Code view. It allows you to search for code by just typing the search text and then jump from one occurrence to another. To use an incremental search, follow these steps:

  1. In the Code view, open the Web page where you want to perform an incremental search.

  2. Press Ctrl+Alt+F to enable an incremental search. The mouse pointer changes, and the status bar at the bottom of the SharePoint Designer window displays Incremental Search: text.

  3. Type some text that you want to search. The Code view jumps to the text and then highlights it.

  4. Press Ctrl+Alt+F to jump to other occurrences of the search text in the Code view. Also, you can press Ctrl+Alt+Shift+F to reverse the direction of the incremental search.

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

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