Posts Tagged ‘SharePoint 2010’

SharePoint Document Library List View Web Part with Clickable Breadcrumbs

I recently had a request to add breadcrumbs to a home page of a SharePoint team site to enable users to navigate easily between folders within a list view web part for a document library. The breadcrumbs would be displayed at the top of the page, below the title, and it would display links to each of the folder levels that the user has navigated into. The solution would have to be generic and work for multiple library list view web parts on the home page. The solution uses javascript stored in a text file that is saved in a site assets library, along with a content editor web part on the page to display the breadcrumb links.

  • This is an image of the home page of a team site with 2 document library list view web parts for Shared Documents and More Shared Documents.


  • As we navigate in to Folder 1 in the Shared Documents library you can see that there is no easy way to get back to the root of the Share Documents library.


  • Here is another level deep, Folder 1.1 in the Shared Documents library. Again no easy way to get back to Folder 1 or the root.


  • This is how the breadcrumb navigation looks like if the user goes to the library itself.





1. The first step is to create a text file that will contain the javascript necessary to generate the clickable breadcrumbs. I called my file LibraryViewBreadCrumbs.txt. Insert the following javascript text in to the file.

// Variable to store the text used by SharePoint to generate the breadcrumb separator arrows

     var SeparatorArrow = ‘: ‘;

     var baseURL = (document.location).toString();

     baseURL = baseURL.substring(0,baseURL.indexOf(“.aspx”)+5);


     var url = baseURL;                             

     url = baseURL + ‘?RootFolder=’;


     var rootFolder = unescape(GetUrlParameter(‘RootFolder’));      

     var path = GetFolderPath(rootFolder);   

     rootFolder = rootFolder.substring(0,rootFolder.indexOf(path));  


     if(path.length > 0)


         var folders = path.split(‘/’);

         for(var i=0; i



                    url += encodeURIComponent(rootFolder.substring(0,rootFolder.length-1));

              url += encodeURIComponent(‘/’ + folders[i]);

              url = url.replace(“%2F%2F”,”%2F”);



                   //Add the folder link and separator arrows if more than one folder level deep

                   document.write(‘‘ + folders[i] + ‘‘);











// Gets the value of the requested URL Parameter

function GetUrlParameter( name )


     name = name.replace(/[\[]/,”\\\[“).replace(/[\]]/,”\\\]”);

     var regexS = “[\\?&]”+name+”=([^&#]*)”;

     var regex = new RegExp( regexS );

     var results = regex.exec( window.location.href );

     if( results == null ) return “”;

     else return results[1];



// Gets the name of the library

function GetFolderPath(rootFolder)


     var domain = window.location.hostname;

     var web = baseURL.substring(baseURL.indexOf(domain)+domain.length);

     var path = rootFolder.substring(GetFirstBreakIndex(web, rootFolder));

     return path;



// Gets the first different character occurrence index

function GetFirstBreakIndex(a, b)


     var slashIndex = -1;

     var equalsReturnCode = -1;

     if (a && b)


          var longest = b.length > a.length ? b : a;

          var shortest = a.length > b.length ? b : a;


          for(var i=0; i


               // Get location of each / as a breakpoint if

               // the first break index is part way into the string

               if(shortest.charAt(i) == ‘/’)

                    slashIndex = i;

               if(shortest.charAt(i) != longest.charAt(i))


                    if(i-slashIndex == 1)

                         return i;


                         return slashIndex + 1;






          return equalsReturnCode;



2. Save this file to the SharePoint site in a library that all users have access to. I stored mine in a Scripts folder in the Site Assets library.


3. Edit the home page of the site to insert a Web Part.


4. Select and Add a Content Editor web part in the Media and Content category.


5. Edit the web part that was just added to the page. In the Content Link block enter the location of the text file saved in step 2 above.


6. You may want to update the Title property to something that notifies other administrator users who can edit that page that this Content Editor web part should not be deleted. I labeled mine with Breadcrumbs Script (Do Not Delete). Then hide the title by setting the Chrome Type to None.


  • This is how the Content Editor web part will be displayed when the page is in edit mode.


  • Initially when the page is loaded there will be nothing displayed in the breadcrumbs, since no folders within the document libraries are selected.


  • If the user selects Folder 1 in the Shared Documents list view web part the breadcrumbs will be displayed.


  • Folder 1.1 selected in the Shared Documents list view.


  • Folder 1.1.2 selected in the Shared Documents list view.


  • Example of selecting Folder 2 in the More Shared Documents list view.



  • Example of selecting Folder 2.1 in the More Shared Documents list view.



E-mail Notification on User Access Denied

I recently had a project that required an e-mail notification be sent to an administrator whenever users received an Access Denied message in any SharePoint site collection. The reason for this was to troubleshoot intermittent access denied issues within a SharePoint 2010 server farm.


The e-mail massage had to include a subject of Access Denied, sent to the administrator, and cc’d to another user. The body had to include the SharePoint site URL, user name, login id, and the address of the server (in order to determine if there was a certain server causing the issue).

In order to accomplish this task we did the following.

1.       Made a backup copy of the AccessDenied.aspx file in 14 hive.

2.       Opened up the AccessDenied.aspx file and added the following script to the top of the page just before the <asp:ContentContentPlaceHolderId=”PlaceHolderPageTitle”runat=”server”> tag.



<script runat=”server” language=”C#”>

protected void Page_Load(object sender, EventArgs e)


    StringDictionary headers = new StringDictionary();




    headers.Add(“subject”,”Access Denied”);

    string messageBody = “Site: ” + SPContext.Current.Web.Url + “, User: ” + SPContext.Current.Web.CurrentUser.Name + “, Login: ” + SPContext.Current.Web.CurrentUser.LoginName + “, ID: ” + Request.ServerVariables[“LOCAL_ADDR”];



        SPUtility.SendEmail(SPContext.Current.Web, headers, messageBody);


    catch (Exception ex)


        LabelUserName.Text = ex.Message;




 3. Now when a user hits the AccessDenied.aspx page the administrator receives the following e-mail message.



SharePoint 2010 Sample Custom Actions Menu Use

March 8, 2013 Comments off

This sample custom actions use was developed to allow users with certain permission to start two workflows manually on list items.  Users who do not have permissions to run the workflows would not see the buttons and cannot start the workflows. Also users who do have the permissions to run the workflows manually should not see the workflow links when selecting “Workflows” option in the Item Menu.

The list for this example is a custom list that includes a Date Approved field and a Date Closed field.  The business process is for users to fill in the list item data, followed by an approval process. The list item is approved and a date is entered manually in the Date Approved field. The next step in the process is to close the item by entering a Closed Date manually. Certain users can run the “Unlock Record” and “Cancel Record” process.

Unlock Record

 This action runs a SharePoint Designer workflow called “Unlock Rec”. The purpose of this workflow is to unlock the record by clearing out the Date Closed first and then clearing out the Date Approved second.


The workflow was set originally to “Allow this workflow to be manually started”, but this option was removed after associating it to the list Custom Action in order to hide it from the “Workflows” screen for users who had permission to run this workflow.


Cancel Record

This action runs a Visual Studio workflow called “Cancel Rec”. This workflow was developed in Visual Studio due to the complexity of the workflow requirements. The purpose of this workflow is to prefix the word “CANCELLED” to a remarks field, flag the record as canceled in a hidden field, and set the “Date Approved” and “Date Closed” based on their current values.

Custom Actions

The custom actions were added for both processes to the List Item Menu, Display Form Ribbon, Edit Form Ribbon, and View Ribbon.


The Cancel Record was the first button to be displayed followed by the Unlock Record (sequence 0 and 1).

User with Permissions

User without Permissions

List Item Menu

List Item Menu

 ListItemMenu  ListItemMenuWithoutPermissions

Display Form Ribbon

Display Form Ribbon

 DisplayFormRibbon  DisplayFormRibbonWithoutPermissions

Edit Form Ribbon

Edit Form Ribbon

 EditFormRibbon  EditFormRibbonWithoutPermissions

View Ribbon

View Ribbon

 ViewFormRibbon  ViewFormRibbonWithoutPermissions

Create Custom Action


The type of action chosen was to Navigate to URL. The reason why this action was chosen over the Initiate workflow was because the users did not want to see the workflow initiation form when starting the workflow.


The page at the Navigate to URL has jquery and javascript on it to run the workflow automatically and return the user to the {Source} url.

The Rights mask chosen was ApproveItems in order to only enable the custom action buttons for users in this group.

This is just one simple example of using the custom actions for a custom list to provide functionality to a specific set of users.



SharePoint Document Library View with Clickable Breadcrumbs

Have you ever found it frustrating that the breadcrumbs generated in SharePoint 2010 for document libraries do not display every folder level when navigating nested folders? The breadcrumbs don’t really help that much to go up one or two folder levels. This post outlines the steps to follow to create a view that has clickable breadcrumbs in the title using javascript and SharePoint designer.

1.       Open the document library

2.       Create a new public view




3.       Save the new view

4.       Edit the list view page in SharePoint designer.


5.       Navigate to Lists and Libraries and select the view. In this scenario select Test in the Views section.


6.       Select Advanced Mode in the Editing section of the Home tab.


7.   Select the Default breadcrumbs which will highlight the TitleBreadcrumb area in the code.


8. Replace this line with the following javascript

<script type=”text/javascript”>

var baseURL = (document.location).toString();

baseURL = baseURL.substring(0,baseURL.indexOf(“.aspx”)+5);

var path = ‘<SharePoint:ListProperty Property=”RelativeFolderPath” runat=”server” />’;

var rootFolder = ”;

var url = baseURL;

document.write(‘url + ‘”>’);

url = baseURL + ‘?RootFolder=’ + rootFolder;

if(path.length > 0)


     document.write(‘ <SharePoint:ClusteredDirectionalSeparatorArrow runat=”server” AlternateText=”>” /> ‘);

     var folders = path.split(‘/’);

     for(var i=0; i < folders.length; i++)


          url += ‘/’ + folders[i];

          document.write(‘url + ‘”>’ + folders[i] + ”);


               document.write(‘ <SharePoint:ClusteredDirectionalSeparatorArrow runat=”server” AlternateText=”>” /> ‘);




9.   Select the List View Selector Menu, add  style=”visibility:hidden” to the span just above the SharePoint:ListTitleViewSelectorMenu tag


10.   Save the file.

11.   Select Yes to the Site Definition Page Warning dialog.


12.   Now you will have breadcrumbs that you can use to navigate through the document library.


Update Content Database Names in SharePoint 2010

These steps apply only to content databases.

1. In Central Administration, take the content database offline.

a. Application Management > Manage content databases

b. Select the database to rename

c. Set the database to Offline

2. In Central Administration, remove the content database from SharePoint. You’ll get a warning here that any sites in that are stored in the content database will no longer be accessible to users. While that is true, it does not mean that you’re deleting sites; the sites and all their data will remain in the content database.

3. In SQL Server, detach the database.

a. Right click on the database and select Tasks > Detach…

b. During this process, it may be necessary for you to also drop all existing connections to the database. Check the Drop Connections box, and select OK.

4. In SQL Server, re-attach the same database.

a. Right click Databases and select Attach…

b. Select Add and locate the mdf file with the same name as your database

c. In the databases to attach grid update the “Attach as” field with your new content database name. Select the OK button to re-attach the database.

5. In Central Administration, Add a content database for your web application

6. Make sure you have the correct web application selected and enter the new content database name from step 4 above in the Database Name box. This will attach an existing content database to the web application, providing you enter then name of an existing content database. If you enter the name incorrectly and it does not match an existing content database name SharePoint will create a new content database with this new name.

7. Click the “OK” button.

8. The database should now appear as an available database in Central Administration.

9. Make sure the Database Status is “Started”. That is it! All site collections that were in the content database should now be available.