Building a list-specific search with JavaScript

Whilst writing an article that looks at the Instant List Filter (hosted on CodePlex) I started wondering if there was an “Out of the Box” search solution that allows users to search within specific lists. It’s a discussion that I’ve frequently seen in the TechNet forums, particularly whenever search scopes are mentioned. Whilst I wasn’t able to locate anything via the SharePoint GUI, there is indeed a way that this can be achieved, simply by using JavaScript and the Content Editor Web Part.

Solution Details

The core solution is to embed some JavaScript code within a Content Editor Web Part (CEWP) and to tweak it for your list / library. Within the source code (HTML view for SP2010) the code snippet entered provides the end user with a dropdown box, a textbox, and two buttons. These buttons are a Search button and a Clear button.

The dropdown list provided will contain a hardcoded list of all the column names that you want to make searchable. The intention is that the user selects the column to search by picking it from the dropdown box, enters his search text and then clicks the Search button.

The JavaScript will then redirect the user to the same page, with query string data appended to the URL. The Clear button sets the query string url back to blank, which in effect clears the search data and ensures that the entire list is back in view.

When search scopes are enabled in SP2010, the option to search the list is automatically included in the list of options. However, search scopes are enabled at the site collection level, meaning that once enabled, all lists within your site collection will get this option. This JavaScript alternative is particularly useful if you want to enable list-level search for specific lists only. It also has the added advantage of allowing results to be displayed in situ instead of redirecting to a search results page. However, rather than jumping straight into the code, let’s look a little at how OOB list filtering works as this is the functionality that the script plugs into.

Looking at the query string in greater detail

  • In your SharePoint site create a list that has a high number of columns. The Contacts list works perfectly for this

  • Next, input a few dummy items. Having a few rows to play with works best. In my example I’ve used two football managers from the UK Premier League as well as the national team manager

  • Now that you have some test data, apply a filter and wait for the page to reload. The demonstration screenshot below applies a filter to the Last Name column.

Script Details & how to amend

  • Step One: On the page that you want to apply the search field to, use Site Actions à Edit Page
  • Step Two: Click Add a Web Part
  • Step Three: Add an HTML Form Web Part or a Contend Editor Web Part, either will work

  • Step Four: Input the code snippet below and make the following changes
    • In the function RedirectURL add the columns you want to make searchable from left to right using the format “Column2”, “Column3” and so on
    • In the same function, locate this text window.location.href = “AllItems.aspx?” and set this to the page you want the search results rendered on. The script has this set to the default view AllItems.aspx. Please note that you MUST keep the question mark in the code.
    • In the Search field you’ll see some options that look like this: – <option
      value=”Title”>.
      These fields need to correspond to the internal name NOT the display name of the
      columns that you want to make searchable. Column internal names are explained very well here.
  • Step Five: Save the file once you’ve made your amendments and your page should reload looking something like the below, with a basic but list-specific search engine at the top of the page

Further usage

There are probably some things that you can do to take this further if so desired. Some of the tweaks I’ve made include: –

  1. Styling the buttons according to branding requirements
  2. Keeping this code in a separate HTML file and linking it within a CEWP
  3. Hiding all but the first selection field to force searching within only one column
Advertisements

How to update Parent Folders Timestamps when Child contents have been modified

Something that SharePoint professionals occasionally get asked is whether it is possible to update a parent folder when child documents within it have been altered. Whilst my first response is to encourage the use of metadata and flatter file structures, it’s fair to assume that this isn’t always achievable. Some teams and personnel are comfortable with folders and don’t see a reason to change.

This blog post shows how you would achieve this using Documents Sets and SharePoint Designer. Document Sets are a bit more flexible than folders. As such this approach doesn’t lend itself well to existing folder structures: –

  1. Create a Site Column called DocSetName. Make it a Single line of text data type
  2. Create a LastModified column. Make it a Date/Time data type
  3. In the document library, where you want to make these changes, activate the management of content types via Document Library Settings à Advanced Settings à Content Types
  4. Click “Add from existing site content types” and add the Document Sets
  5. In the content type section, click on Document Set à Add from existing site or list columns and add DocSetName and LastModified
  6. Next (still within the Document Set Content Type Settings) click on Document Set Settings and scroll down to Shared Columns. Select DocSetName
  7. Next, within SharePoint Designer, create a new workflow at the document library level
  8. Set this workflow to automatically start when an item is created or changed. Using the Update List Item (update item in current list) action set the “LastModified” column to the current document item “Modified” column value. What this means is that any new document “Modified” column will be update the LastModified field of its parent Document Set.
  9. Back in your library, create a view that sorts by LastModified (descending) and you’ll see that the Document Set with the most recently edited item will be on top

The caveat

There is one trade off to getting this working and it’s this. Any new items created within a Document Set MUST have the name of the Document Set manually entered into the DocSetName column. If this isn’t done than the workflow will error out. The reasoning behind this is explained below.

What does the workflow do?

This idea is that each Document Set shares the DocSetName column value with any document contained within it. As set up in step 3 any document that gets created or get modified will trigger the workflow. The workflow effectively goes to find the item whose “Name” column value is equal to current document item “DocSetName” column value. Subsequently it will always find the parent Document Set item and update its “LastModified” column with the current document modified date.

This means that each document set “LastModified” value is always going to be equal to the modified time of one of the child documents within it. Without the DocSetName column on the document level being manually filled, the workflow cannot make the association and will return an error.

That about covers it but let me know if you have any questions, suggestions and so on.

Tutorial: Using the SharePoint List Field Manager

After I’d written the tutorial for the Seadragon Web part, I hit upon the idea of making short introductory guides an additional part of the CodePlex Corner Series. In the course of my playing around with the goodies on offer, I’m typically taking notes for my own records. It’s not really a huge leap to tidy them up and make them available for publication.

I don’t really have a specific format in mind but I’d like to try and make these tutorials as inclusive as possible, especially as some of the projects might not have terribly detailed literature with them. Any part that’s not relevant for more experience readers can always be skipped.

With that in mind, let’s get you started with the SharePoint List Field Manager. This is an easy tool to use, so the tutorial will be brief. We will cover web part installation, then activation and will look at some best practice ideas around it.

Installing the SharePoint List Field Manager

  1. Create a folder on your root drive called Web Parts. This should be something like C:\Web Parts
  2. Download the ListFieldManager.wsp file into this folder
  3. Open the SharePoint 2010 Management Shell. Typically this is Start à All Programs à Microsoft SharePoint 2010 Products à SharePoint 2010 Management Shell. Run this as the administrator
  4. Use the following PowerShell Command to install the wsp file. Add-SPSolution “C:\Web Parts\ListFieldManager.wsp”. Please note that the double quotation marks are needed for the file path. Otherwise, you may generate the positional parameter error message below.
  5. As PowerShell will helpfully tell you the solution is deployed but not installed. Installing the solution is what will make it available for use.
  6. Use this PowerShell command, making sure to change the http://YourApp URL to your own Web Application. This should install with no issues
  7. Once this command has completed the List Field Web Part will be available for use

     

Activating & using the SharePoint List Field Manager

The List Field Manager is a site collection feature and should be activated as such. It activates with no problems. This will be the same for both SharePoint 2007 & SharePoint 2010. The end product is a web part that you deploy and use to configure your lists: –

  1. Navigate to Site Actions à Site Settings à Site Collection Features and activate the web part. It is listed under SharePoint List Field Manger.
  2. Now that the web part is available it will be in the Web Part Gallery. It will appear under the SharePoint Management category
  3. Once the web part has been added to a web part zone you can feed it the URL of the site where you want to manage the lists. Please be aware that you cannot access lists in other sites if you are using the SharePoint 2010 SandBox deployment. Either way click on Display Lists
  4. The web part reloads with a List drop down, which is populated with all available lists for the site that was selected. Select a list and then click on Display Fields
  5. This will reload the web part again with a second drop down list from which you can select the field that you want to modify. Make the appropriate choice and then click Display Field Settings
  6. The web part reloads again with all available options for that field. The end configuration will look like this

Best Practice / Suggestions

These are some ideas and thoughts that struck me as I was using the SharePoint List Field Manager as things that I’d do when introducing the web part into any of my deployments. My current suggestions are: –

  1. Customising a View field to act as an List Admin Page

Best Practice #1: Setting up a List Admin Page

A useful trick I’ve found is to place the List View Manager within a page that’s associated with its usage. This simply consists clearing out the contents of a View Page and adding the web part in its place.

  1. Within your list or library enter the List Settings and scroll down to the Views Section
  2. Click on Create view. This loads a new page where you select the view format
  3. Click on Standard View
  4. This loads a new page where the view is configured. Forget about configuring anything here; just call the view something like List Field Admin Page. This can also be set up as a personal view. Click Ok. This loads a new page with the standard view
  5. On this page, get into the page editing mode via Site Actions à Edit Page
  6. Edit the web part from this view and set the hidden field under the Layout options
  7. Add the List Field Manager and move this to the top of the page
  8. You will now have an administration view with the List Field Manager present for future configuration

Tutorial: Adding a Deep Zoom Image to a SharePoint 2010 Site

In my previous blog entry (part of the CodePlex Corner Series) I mentioned that I’d write a tutorial on how to add a Deep Zoom Image to a SharePoint site with the Seadragon Viewer web part. These are the notes I’d taken when I was playing around it. I’ve tided them up and they will guide you through the process of web part installation, image creation and how to bring these together.

Applies to

  • SharePoint 2010 (All Editions)

Scenario

You’ve got a large image that you want to distribute to some colleagues. But the image size makes it unwieldy to distribute via email. Instead, you’d like to provide an online capability where your users can interact with the image without losing image integrity. An example of Deep Zoom technology in use can be seen on the SharePoint 2013 architecture diagrams. This solution has a few components, namely: –

  • Seadragon Ajax Viewer Web Part (hosted on CodePlex)
  • Deep Zoom Image Composer
  • A large resolution image

Downloading and installing the web part

First we’ll begin by downloading and installing the web part. We won’t worry too much about configuring it at the moment; all we’re concerned with is getting it onto your servers. These steps should be done from one of your WFE Servers: –

  1. Navigate to the Downloads page of the CodePlex project. The SeaDragonViewer.wsp is the recommended download at the top of this page
  2. Create a folder on your C drive called C:\Web Parts and download the WSP file to this directory
  3. Open the SharePoint 2010 Management Shell via Start à All Programs à Microsoft SharePoint 2010 Products à SharePoint 2010 Management Shell. Right-click on this and select the Run as Administrator
  4. Once this has loaded. Run these PowerShell Commands. The first command installs the solution; the second command deploys it and makes it available for selection within your SharePoint installation.
    1. Add-SPSolution “C:\Web Parts\SeaDragonViewer.wsp”
    2. Install-SPSolution –Identity SeaDragonViewer.wsp –WebApplication http://YourSite –GACDeployment

Please note that the http://YourSite should be replaced with the URL of your own SharePoint Web Application. Once these steps have been completed, you’ll have the web part ready and installed for use but no image to plug into it. To prepare these, it’s necessary to step back from SharePoint for a moment and to use another Microsoft Tool; the Deep Zoom Composer

Creating DeepZoom Images for use within SharePoint

In this next set of steps we are going to obtain a high resolution image and use a special image utility to prepare this for use within SharePoint. We will then manually tweak the output of the tool to make sure that it’s compatible with the web part that you downloaded and installed earlier.

  1. On your desktop, create a folder called “Sea Dragon Images”
  2. Next, in your browser of choice navigate to morguefile.com. This is a free photo archive that you can use images fairly freely from.
  3. In the search box, type in London and hit enter
  4. Pick an image on the search results page and click on it. You’ll get a properties box that describes the attributes of the file you’ve chosen
  5. Click on the Download button on this attributes page.
  6. This will prompt you to open the file, save it or to cancel the download. Click on “Save” and save it to the Sea Dragon Images folder that you made earlier

At this point, you should now have a folder with one high resolution image contained with it. To make use of this image we are going to install a piece of kit called the Deep Zoom Composer. This is a facility that takes high resolution images and then transforms them into the appropriate format.

  1. Download the DeepZoom Composer from http://www.microsoft.com/en-us/download/details.aspx?id=24819
  2. The download process is quick and painless. Double click the exe and start the installation process. Accept the terms and conditions and follow the wizard through to completion
  3. Launch the Deep Zoom Composer from the start menu. Start à All Programs à Microsoft Expression à Deep Zoom Composer. You’ll be greeted with this screen
  4. Click on New Project
  5. In the New Project Dialog Box that pops up, name the project “London” and save it to the Sea Dragon Images directory that you created earlier and click OK
  6. With these settings in place, the dialog box will disappear and you’ll see a blank canvas. This has also created a London directory within the Sea Dragon Images directory that you will be investigating later
  7. Back on the canvas, look at the top right of the Zoom Composer and you’ll see an “Add Image” button
  8. Click on this and then navigate to the image that you downloaded earlier. Select it and press Ok. You’ll then see the image selected at the centre of the canvas and on the right hand side of the screen under a thumbnail strip
  9. On the toolbar at the top of the page, click Compose
  10. This will take you to the second stage of the composition process. You will see a blank canvas again but this have the London image from the previous step loaded in the thumbnail strip at the bottom of the screen
  11. Drag the London image from the thumbnail to the canvas. It is beneficial here to use the “Fit to Scree” command to make this easier. Do this via
    1. Edit à Fit to Screen
    2. Keyboard Shortcut: Ctrl + O
  12. Once this is done, you should have a screen that looks similar to the below
  13. Click on the Export Tab
  14. This will take you to a new export page where the various export settings can be inspected. On the export settings on the right hand side of the screen select Seadragon Ajax from the Output type options.
  15. Give your export a name and select the export location. By default this will be a folder called “Export Data” within the project directory that was created when the project was initialised
  16. Click Export once you are happy with the settings. You’ll see these options at the end of export process
  17. Click “Preview in Browser” to see how this will look in your SharePoint site
  18. Once you’ve done inspecting your work in the browser, click on the View Image Folder. You’ll see something similar to the image below. The file path will be …/Exported Data/London/GeneratedImages

Let’s inspect these files before moving on. Some changes will be needed to them shortly but it always helps to know what these are before altering them

File / Directory Name

Notes

Dzc_output_files

Directory containing the zoom images

Dzc_output.xml

XML file that dictates the zoom template size and format

Scene.xml

XML file containing the instructions and calculations for the images

SparseImageSceneGraph.xml

XML file that stipulates the zoom ratio, image path and background colours

 

The two items that we want to pay attention to here are the dzc_output_files directory and the dzc_output.xml. These are the files that the Seadragon Viewer web part needs to talk to. These next steps will show you how to combine your image output and the web part.

  1. In the Generated Images directory generated by the Deep Zoom Composer rename the dzc_output_files directory and the dzc_output.xml to London.
  2. Once these files have been renamed upload the entire directory and the xml files to a SharePoint document library. Right click the London.XML file and copy the shortcut
  3. Back in your SharePoint environment, navigate to the root site of the web application that the web part was installed to
  4. Access the Site Collection Features via Site Actions à Settings. This will load a new screen
  5. On this new screen, look for the Site Collection Administration heading and click on the Site Collection Features under it. This will also load a new page
  6. On this page, search for the SeaDragonViewer Feature1 and activate it. This adds the web part to the web part gallery for all sites within this site collection
  7. Now that the part is available, navigate to the page or site where the Seadragon viewer is to be added. When selecting the web part it will be grouped under the Innovation category
  8. Once the web part has been added, enter the configuration options (Edit Page à Edit Web Part) and look for the miscellaneous section. This will have three configuration options: –
    1. XMLPath: This is where the URL for the renamed XML file needs to be placed
    2. WPWidth: Setting for the Web Part Width
    3. WPHeight: Setting for the Web Part Height
  9. Paste the link of the XML file that you copied earlier into the XML Path field and press Apply / OK
  10. You will now have a web part with a high resolution image that you can zoom into and pan around without any loss of quality

That’s

Updated – Approve or Reject multiple items in a SharePoint 2010 list

Very nice solution for SharePoint 2010 bulk approval.

Ian Ankers's SharePoint Blog

I’ve updated the solution which allows for multiple items to be approved or rejected in a SharePoint 2010 list.  The original post can be found here.

The original solution was built to serve a specific purpose but due to the comments received I’ve now updated it to be more generic and made the following improvements.

  • The solution will work for almost any list or library.
  • It supports language packs and will be fully localised.
  • The source code is available.
  • The ribbon button will only appear if you have rights to approve items.
  • Resolved an issue with the modified by field appearing as the System Account.
  • Changed the way the button appears in the ribbon to use Tooltips.

These are the links to the compiled solution and the source code.

View original post