SharePoint 2007 – Branding Your Site Application Pages

If you’ve ever tried to customize the branding of a MOSS 2007 or WSS 3.0 site you’ve probably discovered that SharePoint application pages (pages that physically reside in the /_layouts folder on the file system) share a common master page and thus share the same style sheets.  Said another way; unlike SharePoint site collections and sites (where you can change the branding of sites by specifying different master pages and style sheets per site) your application pages all use the same master page (application.master) across all site collections and sites on a web application.

Examples of application pages include the following: groups.aspx, editview.asp, pagesettings.aspx, people.aspx, viewlsts.aspx … and many more, about 426 .aspx files in all.

To customize the branding on application pages I came up with a simple technique to dynamically apply different style sheets to the application.master by adding some C# code to the application.master file.  The instructions and sample code below assume that you want to load one of two style sheets depending on the host name (in this case we look for http://mosssitename/ and load the style sheet named css1.css otherwise we load the style sheet named css2.css)

1.  Add the following code inside the <HEAD> </HEAD> tags on your application.master file.

<asp:literal id="DynamicCSSLiteral" runat="server"/>
<script runat="server"> 
  protected override void OnLoad(EventArgs e) {     
    switch(Request.ServerVariables["HTTP_HOST"].ToString()) 
    {
        case "mosssitename":
            this.DynamicCSSLiteral.Text = "<link rel=stylesheet type=text/css href=/_layouts/1033/styles/css1.css />";
            break;
        case "localhost":
            this.DynamicCSSLiteral.Text = "<link rel=stylesheet type=text/css href=/_layouts/1033/styles/css2.css />";
            break;
        default:
            break;
    }
  } 
</script> 

2.  Modify the top line of your application.master file so that the @Master reference has the value AutoEventWireup=”true”.

<%@ Master AutoEventWireup="true" language="C#" %>

Feel free to reply to this post if you find any other solutions to branding application pages in SharePoint 2007.

SharePoint 2007 – Move Content and Configuration Databases

If you’ve ever wanted to relocate your WSS 3.0 or MOSS 2007 content databases or configuration database from one SQL server to another, you’ve probably found very little documentation and very little written on this topic.  Below is my attempt to provide some guidance for these tasks.  The steps are fairly simple, but please remember to try all operations of this magnitude on a development or test environment before trying this on your production SharePoint environment.

Move SharePoint Content Databases

Several common reasons for needing to move a content database from one SQL server to another are:

  • Scalability (spreading the load of your SQL server across multiple SQL servers)
  • Disaster Recovery (your SQL server had a catastrophic disaster and you need to recover from that event)
  • Database Reorganization (you simply need to change the server that hosts your content database or rename the database)

Instructions for moving a content database from one SQL server to another

  1. Detach the content database from the source SQL server and copy the .mdf and .ldf to the target SQL server. (Note: while you are moving the database files your users will see “Cannot connect to content database” when visiting their site)
  2. Attach the .mdf and .ldf files on the target SQL server as a new database (Note: this is your opportunity to rename the database if you desire)
  3. Run the following stsadm commands from the command line on your SharePoint server to complete the move:  (Note: the deletecontentdb does not actually delete the database from SQL server, it simply disconnects the database from SharePoint)

stsadm –o deletecontentdb –url http://yoursiteurl –databasename your_content_db –databaseserver source_SQL_server
stsadm –o addcontentdb –url http://yoursiteurl –databasename your_content_db –databaseserver target_SQL_server

Move SharePoint Configuration Database

Several common reasons for needing to move your configuration database from one SQL server to another are:

  • Disaster Recovery (your SQL server had a catastrophic disaster and you need to recover from that event)
  • Database Reorganization (you simply need to change the server that hosts your content database or rename the database)

Instructions for moving a configuration database from one SQL server to another

  1. Backup configuration database from the source SQL server
  2. Restore the backup onto the target SQL server (Note: this is your opportunity to rename the config database if desired)
  3. Run the following stsadm commands from the command line on your SharePoint server to complete the move:  (Note: the deleteconfigdb does not actually delete the database from SQL server, it simply disconnects the database from SharePoint)

stsadm -o deleteconfigdb
stsadm –o setconfigdb -connect –databaseserver target_SQL_server -databasename databasename -farmuser your_farm_sql_account -farmpassword your_farm_sql_password

 

The complete syntax for the stsadm -o deleteconfigdb is listed below: (Note: there are NO options)

stsadm.exe -o deleteconfigdb

 

The complete syntax for the stsadm -o setconfigdb is listed below:

stsadm.exe -o setconfigdb

           [-connect]

           -databaseserver <database server>

           [-databaseuser <database user>]

           [-databasepassword <database user password>]

           [-databasename <database name>]

           [-hh]

           [-exclusivelyusentlm]

           [-farmuser]

           [-farmpassword]

           [-adcreation]

           [-addomain <Active Directory domain>]

           [-adou <Active Directory OU>]

SharePoint 2007 – "Back" Link After Deleting a Site

After deleting a site in WSS 3.0 or MOSS 2007 the following page is displayed by default.  The “webdeleted.aspx” is a default application page provided by Microsoft, but it is easily customized.  In this article I will show you how to enhance this page to be more user friendly.

delete

The problem with this page is that the user is left hanging, with no links back to the parent site or site collection where the site was deleted from.  Below is a quick solution for adding a link labeled “Go back to parent site” to the top of this page.  When the steps are complete your users will see the following:

delete2

Steps for adding the “Go back to parent site” link.

  1. In notepad, open the file named “webdeleted.aspx” in the 12 hive, layouts folder (usually this is located at the following location: C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS )
  2. Located the content placeholder tag: <asp:Content ContentPlaceHolderId=”PlaceHolderTitleBreadcrumb” runat=”server”>
  3. Add the following code inside the content placeholder:  <a href=”<%SPHttpUtility.HtmlEncode(SPControl.GetContextSite(Context).Url, Response.Output);%>”>Go back to parent site</a>
  4. Save the “webdeleted.aspx” file.

When you are finished the code should look like the following:

<asp:Content ContentPlaceHolderId=”PlaceHolderTitleBreadcrumb” runat=”server”>
     <a href=”<%SPHttpUtility.HtmlEncode(SPControl.GetContextSite(Context).Url, Response.Output);%>”>Go back to parent site</a>
</asp:Content>

SharePoint 2007 – Migrating Fileshare Files into Document Libraries using Migration Tool

We all know that SharePoint document libraries are much more functional that NTFS file shares because SharePoint provides a searchable, indexable metadata framework.  As a SharePoint consultant I am often asked the question: How do I migrate my documents from my file server into SharePoint?  The answer really has to do with answers to the following questions:

  • Do you want to retain the document CreatedBy and CreatedDate values?
  • Do you want to load the document metadata into SharePoint columns (Author, Document Title, Summary, etc.)?
  • How many documents do you want to move to SharePoint?
  • Do you need to fix the names of documents and folders that do not comply with the SharePoint 2007 naming standards? (see the file name rules and folder name rules at the bottom of this post)
  • Do you need to automated the process of importing documents?
  • Do you need complex logic and rules around what documents to import and their destination locations?
  • Do you need to inventory your documents before importing them?

I have used several techniques to move documents into SharePoint document libraries and below I highlight the benefits and drawbacks of each technique:

SharePoint File Upload

Out of the box SharePoint 2007 provides several options for uploading documents into SharePoint document libraries.  These options include: Upload Document dialog, Upload Multiple Documents dialog and Windows Explorer drag and drop.  None of these options allow you to include the document metadata or maintain the CreatedBy, CreatedDate values so they are of limited use.

Pros:

  • The tools are built into SharePoint (no additional software to purchase)
  • No deployment steps

Cons:

  • Document metadata cannot be loaded
  • File CreatedBy and CreatedDate attributes are lost
  • No auditing or batch process
  • Files and folders with bad names will fail to upload and stop your uploading process

Metalogix FileShare Migration Manager

On the more expensive side of the spectrum is FileShare Migration Manager by Metalogix.  This tool provides the most advanced features and functions of any of the tools I’ve seen.  This tool is a bit more expensive than the others, but if you are working on a large migration of documents into SharePoint and there are complex rules for importing those documents (file renaming, logic to determine the destination, logic based on the metadata) then this is the tool for you.

Pros:

  • Load many types of metadata and you can define complex logic and rules related to the metadata
  • Ability to inventory your documents prior to importing them
  • Auto generate sites, document libraries and folders
  • Advanced framework for writing custom transformations
  • Can be fully automated

Cons:

  • Most expensive tool of the ones I’ve looked at

DockIT for SharePoint 2007

Another great tool is DockIT for SharePoint 2007 by Vyapin Software Systems.  This tool is a fairly inexpensive tool that provides the basic features necessary to perform migrations from Fileshares into SharePoint.  While this tool lacks some of the more advanced features and complex logic for complicated migrations, this tool does a good job of moving documents into SharePoint and is quite easy to use.

Pros:

  • Fairly inexpensive tool (we purchased the tool for just under $1000 US)
  • Can load files and extract metadata from the documents
  • Can maintain the CreatedBy and CreatedDate values
  • Sophisticated file renaming and file filtering engine
  • Can be fully automated
  • Simple to use

Cons:

  • Limited in it’s ability to deal with complex migration issues

CodePlex – SharePoint Migration Framework

Last, but not least, is an open source tool on CodePlex called SharePoint Migration Framework.  This tool, and set of accompanying source code, is free to use but does require more experience and research to get up and running in your environment.  I wouldn’t recommend this solution for end-users but if you have SharePoint development experience (and plenty of time) this may be the best tool for you.  This tool comes in two parts: the FileShare Data Extractor (which extracts your fileshare files into the correct format) and the SharePoint Importer (which then loads the files into SharePoint 2007).

Pros:

  • It’s free
  • Can load files and extract metadata from the documents
  • Can maintain the CreatedBy and CreatedDate values
  • Source code is provided for you to extend it’s functionality

Cons:

  • More difficult to use and to configure for complex migrations
  • Requires programming changes to perform more complex tasks

 

I hope this summary of the current SharePoint 2007 fileshare migrations tools is useful to you.  Please add a comment if you find additional migration tools that warrant adding to the list.

Appendix: SharePoint 2007 File and Folder Naming Rules

File Naming Rules

  • Invalid characters: ” # % & * : < > ? \ / { | } ~ 
  • Cannot be longer than 128 characters
  • You cannot use the period character consecutively in the middle of a file name
  • You cannot use the period character at the end of a file name
  • You cannot start a file name with the period character

Folder Naming Rules

  • You cannot use the following characters anywhere in a folder name or a server name:  ~ # % & * { } \ : < > ? / | ”
  • Cannot be longer than 128 characters
  • You cannot use the period character consecutively in the middle of a folder name
  • You cannot use the period character at the end of a folder name
  • You cannot start a folder name with the period character

SharePoint 2007 – LDAP User Filters for Limiting User Profile Import

If you’ve ever tried to setup SharePoint 2007 to import user profiles via LDAP you’ll like this post.  The setup of the SSP to import profiles is a fairly simple task, but what is not that easy is applying the right LDAP user filter to import only the accounts that you desire from Active Directory.  I’d like to share with you my experience with applying user filters and some of the excellent user filter examples I have found.

Instructions for creating a new connection and applying an LDAP user filter to limit the profiles imported by your Shared Service Provider:

1. Log in to your SharePoint Central Administration site.
2. Select your Shared Service Provider and click on “User profiles and properties” under the “User Profiles and My Sites” column.
3. Click on the link, “Manage Connections”.
4. Click on “Create New Connection”.
5. Give the connection a meaningful name.
6. In the Directory service server name text box, enter the server name or IP address of your LDAP server.
7. Enter the LDAP user filter of your choice (see below for examples) .

Now you are ready to import your LDAP users into the profile database. Go back a screen and start a full import. Once the import starts enumerating you should see user profiles being imported into SharePoint. When the import is complete, click “View Profiles” to see what profiles were imported.

I’ve compiled a fairly good set of user filters below, feel free to submit a comment if you have others to add to the list.

Example LDAP User Filters

Default user filter:
(&(objectCategory=Person)(objectClass=User))

Exclude accounts with no email address:
(&(objectCategory=Person)(objectClass=User)(!(userAccountControl:1.2.840.113556.1.4.803:=2))(mail=*))

Exclude disabled accounts:
(&(objectCategory=person)(objectClass=user)(!userAccountControl:1.2.840.113556.1.4.803:=2))

Exclude accounts with passwords set to expire:
(&(objectCategory=person)(objectClass=user)(!userAccountControl=65536))

Include only the accounts with valid email addresses
(&(objectCategory=Person)(objectClass=User)(mail=*com)

Include only the accounts that are part of the Branch1 organizational unit
(&(objectCategory=Person)(objectClass=User)(memberof:1.2.840.113556.1.4.1941:=(CN=Authenticated Users,OU=Branch1,DC=domain,DC=local)))

Exclude accounts that don’t have a first name
(&(objectCategory=Person)(objectClass=User)(!(userAccountControl:1.2.840.113556.1.4.803:=2))(!(!givenName=*)))

Other Resources

Wayne Hall – Importing only a specific group into sharepoint profile database (via LDAP)

MSDN – Active Directory Search Filter Syntax

LDAP Documentation – LDAP Attribute List

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:

Configure MOSS 2007 Site Usage Reports

SharePoint 2007 has built in usage reports that can easily be enabled to allow site administrators and site collection administrators to monitor statistics about the use of their sites. These reports are NOT turned on by default when install MOSS 2007.

Three Quick Steps to Configure Site Usage Reporting

  1. Enable Usage Logging in Central Administration
    A. On the Central Administration home page, click Operations.
    B. On the Operations page, in the Logging and Reporting section, click Usage analysis processing.
    C. On the Usage Analysis Processing page, in the Logging Settings section, select Enable logging.
    D. Type a log file location and number of log files to create.
    E. In the Processing Settings section, select Enable usage analysis processing, and then select a time to run usage processing.
  2. Enable Usage Reporting on SSP Admin Page 
    A. On the SSP home page, in the Portal Usage Reporting section, click Usage reporting.
    B. On the Configure Advanced Usage Analysis Processing page, in the Processing Settings section, click Enable advanced usage analysis processing.
    C. In the Search Query Logging section, select Enable search query logging.
  3. Activate the Reporting Feature for the Site Collection
    A. On the Site Actions menu, click Site Settings.
    B. On the Site Settings page, in the Site Collection Administration section, click Site collection features.
    C. On the Site Collection Features page, click the Activate button for the Reporting feature.

After site usage reporting is enabled the site administrators and site collection administrators will be able to view reports detailing:

  • Requests and queries in the last day and the last 30 days
  • Average number of requests per day over the last 30 days
  • Requests per day over the last 30 days
  • Top page requests over the last 30 days
  • Top users over the last 30 days
  • Top referring hosts over the last 30 days
  • Top referring pages over the last 30 days
  • Top destination pages over the last 30 days
  • Top search queries for the last 30 days
  • Search results top destination pages
  • Number of search queries per day over the previous 30 days
  • Number of search queries per month over the previous 12 months
  • Top search queries over the previous 30 days
  • Search Queries per search scope over the previous 30 days

Site collection administrators will be able to view reports detailing:

  • Total amount of storage used by the site collection
  • Percent of storage space used by Web Discussions
  • Maximum storage space allowed
  • Number of users for all sites in the hierarchy
  • Total hits and recent bandwidth usage across all sites

Using the Source Query String Parameter in SharePoint 2007

Have you ever wanted to direct users back to where they came from after submitting a form.  On most SharePoint 2007 forms you can simply add an element to the query string for SOURCE and SharePoint will automatically redirect the user to a specified page when the form is submitted.  For example:

A form named: http://myintranet/site1/Form1.aspx can automatically redirect the user to the homepage http://myintranet/default.aspx by changing the link to the form to be:

http://myintranet/site1/Form1.aspx?source=http://myintranet/default.aspx

This can be a handy feature when you want to create a special confirmation page.  InfoPath forms can take advantage of the same technique by adding values to the query string source parameter, read more.

More information on this topic can be found at:

Using the current page URL in the urlaction of a SharePoint feature by Jan Tielens

InfoPath Forms Services – What happens after a form is closed by Itay Sharkury

Other SharePoint querystring parameters by Daniel McPherson

SharePoint 2007 Visio Stencil

Have you ever wanted to create beautiful SharePoint site diagrams using Microsoft Visio?  I recently created a stencil for Visio that includes all the important objects when creating diagrams for SharePoint 2007 projects.

image

The stencil includes unique SharePoint 2007 shapes for; Site, Subsite, Portal subsite, Search Center, Site Directory, Meeting Workspace, BDC Data, Calendar, Check List, Contacts, Discussion, Document Library, Event, Form Library, Gantt Chart, Issues list, KPI, Links, Locked Document Library, News, Survey, Task list, Approval, Form, and Farm.

image

It also includes shapes for; Firewall, User, Active Directory, Server, SQL, Folder, Document, and others.

Download the Visio Stencil

(Please note: You may need to right-click and save this file as a .vss file, Windows may try to rename this file as a .vsd but Visio stencils must be named .vss to work properly.  You can also rename the file after downloading)

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: