SharePoint 2007 – Page Redirection / Bad Links Solution

Recently I was faced with this customer situation: “Replace my existing web site with a SharePoint 2007 site AND handle all the existing links to my site gracefully”.   Basically the customer asked me to build them a new public facing web site and asked that their existing page links (those in search engines, other web sites and links saved by their customers) continue to work and don’t become “dead” links.

I’ve heard this request when building Intranet sites and Extranet sites, but it’s probably most important when SharePoint 2007 replaces an existing Internet site because you have less control and contact with the audience.  With Intranet and Extranet sites you often have the ability to notify site users that the links to their sites and documents may be broken and you may even provide documentation and training on how to deal with the new site taxonomy.  With Internet sites you don’t have the same relationship with your users (customers) so your SharePoint 2007 site often has to handle the old links gracefully. 

With public facing sites you often reply upon search engines (Google, Live Search, Yahoo, etc) to find your site and you want to be sure that the stale links in those search engines do not lead to dead ends.  Most search engines today provide webmaster tools that allow you to remove dead links and provide updates site maps.  See my article on site maps for SharePoint.   Below are links to the three most popular search engine webmaster tools:

There are two basic approaches for solving the page redirection and bad link issues; 1.  Translate the http requests before they reach the site, or 2. Make the site “smart” so that it can redirect the http requests to the appropriate destination.

Things to consider before you begin building a solution:

1.  Identify all potential inbound links to your site and document those (I recommend creating a SharePoint list or spreadsheet).  Be sure to visit all major search engines to see what pages are indexed by those search engines, those links should be included in your list.

2.  Determine if your inbound links use query string parameters; for example: a link like http://www.kroger.com/privacypolicy.htm does not use query string parameters where a link like http://www.kroger.com/page.asp?tabid=143 does use query string parameters.  This will depend heavily on the technology used to implement the site you are replacing and may impact your choice on solutions.

3.  Identify the tools at your disposal; For example; is there a hardware-based firewall, a software-based firewall, load balancing software, load balancing hardware.  It is often easier to leverage one of these tools for page redirection rather than going down the custom programming path.

Solutions for handling page redirection include the following:

1.  Firewall or Load Balancing – Configure your firewall to “listen” for the set of inbound links and have your firewall redirect the request to the desired destination page.  If you are using Microsoft ISA Server you can enable Link Translation to handle the transition to the new addresses.  Other firewalls and load balancing solutions provide similar functionality to ISA, so be sure to check with your vendor.

2.  Custom Redirection Page – Implement a custom ASP.NET page inside SharePoint to handle all 404 errors.  

3.  Use the Codeplex Smart 404 Feature created by Josh Carlisle.  This is the solution I’ve used the most and I’ve found it very effective. 

In my next post I will guide you through the use of the Smart 404 Feature and provide you some sample code for extending the functionality of that feature.

SharePoint 2007 – Hiding fields on NewForm.aspx and EditForm.aspx, the easy way

One of the limiting factors in using the default forms (NewForm.aspx, EditForm.aspx) is that there is no obvious way to hide columns from appearing in the form.  By default all columns in a list or document library will appear in your forms. 

After doing quite a bit of research on this I found a fairly easy way to hide fields by using JavaScript within the form pages themselves.  In my research I found several different sets of JavaScript code, but some of the scripts are easier to implement than others.  Below I provide the best and most straight forward JavaScript and some simple steps to guide you along.

To hide fields in a SharePoint 2007 form, follow these steps (I will use the NewForm.aspx in my example)

  1. Open SharePoint Designer and navigate to the site that contains the list or document library you wish to customize.
  2. Expand the folder named “Forms” under the desired list or document library.  You should see about seven .aspx pages (AllItems.aspx, EditForm.aspx, NewForm.aspx, etc)
  3. Open the NewForm.aspx page and switch to the “code” view to edit the HTML of the page.
  4. Paste the JavaScript code immediately below the the following HTML tag <asp:Content ContentPlaceHolderId=”PlaceHolderMain” runat=”server”>  This will add the JavaScript to the HTML inside the content placeholder tag.  Note: be sure to include the entire script below, including the <script and </script> tags.
  5. Modify the “hidefields()” section of the JavaScript code to refer to each SharePoint list field name to hide.  For example, the code sample below will hide the SharePoint fields named Title, Document Link, and PublishDate    Notice that you do not need to worry about internal field names or field types like other JavaScript techniques, you simply need to know the name of the field.
  6. Save the changes.  Select “Yes” when prompted to “…customize the page from the site definition…”
  7. Test the form

 

<script language="javascript" type="text/javascript">

_spBodyOnLoadFunctionNames.push("hideFields");

function findacontrol(FieldName) {

   var arr = document.getElementsByTagName("!");
   // get all comments
   for (var i=0;i < arr.length; i++ )
   {
      // now match the field name
      if (arr[i].innerHTML.indexOf(FieldName) > 0)
      {         return arr[i];      }
   }
}

function hideFields() {

   var control = findacontrol("Title");
   control.parentNode.parentNode.style.display="none";
   control = findacontrol("Document Link");
   control.parentNode.parentNode.style.display="none";
   control = findacontrol("PublishDate");
   control.parentNode.parentNode.style.display="none";

}
</script>

 

I hope you find this technique for using JavaScript to hide form fields in SharePoint 2007 as useful as I did.  Thanks to the guys at CleverWorkarounds for writing an article on this.

SharePoint 2007 How To List

After several projects implementing MOSS 2007 and WSS 3.0 I’ve collected a large list of “How to …” type links.  I’d like to share these with you, feel free to send me comments to add to this list:

Employee Directory using User Information List in SharePoint 2007

Recently I was asked to create an employee directory page on SharePoint 2007 intranet to display all the employee profiles in a single list, and make the list searchable.

Goals:

  1. Display a complete list of all Active Directory profiles imported by the SSP into SharePoint 2007.
  2. Display the following fields on the list: First Name, Last Name, Department, Job Function, Email Address, Photograph
  3. Allow the user to resort the list by First Name, Last Name, Department
  4. Allow searching of the list by First Name or Last Name
  5. Allow grouping of the list by Department
  6. Provide link to each employee’s person.aspx page display other details about the employee.

I found a hidden list in SharePoint 2007 called the “User Information List” which appeared to be exactly what I needed.   I was able to expose the User Access List by using SharePoint Designer to enable changing the permissions on this list.  This is done by opening the root of the site collection in SPD, navigating to the list name “User Information List” in the _catalogs folder, then right clicking the list to select the option for “Manage permissions using the browser”.   Then I was able to grant permission for all users to see this list.

Next I was able to customize the views in this list to allow the appropriate fields to be displayed, sorting to be specified and for a grouping by department.  This all seemed awesome and I was quick to show everybody how cool this new list I found was. 

Now here’s the rub; I noticed that the User Information List was not in sync with the profiles imported from Active Directory by the SSP.  After doing more research I realized that the User Information List is not tied to the profile database at all but is simply a listing of the users that have ever been granted access to the site collection.

What I learned:

  1. In MOSS 2007 the User Information List and the profile database (the one populated by SSP import) are independent and do not update each other upon changing.
  2. Each site collection has it’s own User Information List and the User Information List is populated at the time in which a user is first granted access to a site collection.  Andrew Connell (MVP) does an excellent job explaining more about this here.
  3. To create an accurate Employee Directory the best solution is to do one of the following:
    • Direct users to the built in People Search to lookup employees.
    • Create a custom web part that queries the profile database and displays the profiles in a list form.
    • Purchase a third-party web part like the ASI Advanced Employee Directory web part.
    • Purchase the User Sync Tool by Bamboo Solutions to keep the User Information List in sync with the profile database.
  4. There are some simple ways to add wildcard search functionality to the built-in MOSS People Search and use the People Search for the Employee Directory.

Additional Resources on this Topic: