Thursday, January 31, 2013

List of "illegal" characters that cannot be included in a SharePoint file name

I've been working on a utility that our team is going to leverage for rapidly uploading a ton of existing Policy and Procedure documents from file shares into a SharePoint site (by the way, this includes defining the relevant document metadata which is why we aren't simply copying the files over).  During my investigation, I happened to notice that many of the file names in the file share contain characters that SharePoint is not going to like at all (i.e. '&' is the leading offender).  In case you're curious what these "illegal" characters are for file names, here is a complete list:

  • Tilde
  • Number sign
  • Percent
  • Ampersand
  • Asterisk
  • Braces
  • Backslash
  • Colon
  • Angle brackets
  • Question mark
  • Slash
  • Pipe
  • Quotation mark

The source of this information is the following link: http://support.microsoft.com/kb/905231

If you're looking for a solution to this problem, one option is to use the code that I created in one of my previous posts that will allow you to rename the file as you're adding to to your document library:  Remove special characters from a string using Regular Expression


Thursday, January 24, 2013

How to find SharePoint 2013 Central Administration

I know that I'll be laughing about this post in the future, but I've got to be perfectly honest and tell you that it took me nearly 20 minutes to figure out how to access SharePoint 2013 Central Administration in my new Windows 2012 Server environment.  Here two different methods that I finally stumbled upon ways that will make this happen:

Method 1:
  1. Log on to your Windows 2012 Server environment
  2. Click on the center of the screen
  3. Move your mouse to the upper right corner of the screen and a panel will appear on the far right side of the screen
  4. Click on the Search icon

  5. Locate the Microsoft SharePoint 2013 section
  6. Click on the SharePoint 2013 Central Administration icon


Method 2:
  1. Log on to your Windows 2012 Server environment
  2. Click on the center of the screen
  3. Move your mouse to the upper right corner of the screen and a panel will appear on the far right side of the screen
  4. Click on the Start icon


  5. Move your mouse to the bottom of the screen and right click
  6. Click on the All Apps icon


  7. Locate the Microsoft SharePoint 2013 section
  8. Click on the SharePoint 2013 Central Administration icon
If it makes things easier, you can pin this icon to the Start page or Taskbar by replacing steps 6 and 8, respectively, as follows:
  1. Right-click on the SharePoint 2013 Central Administration icon 
  2. Click on the appropriate pin option icon

Tuesday, January 22, 2013

Programmatically obtain a list of SharePoint Web Applications located under a SharePoint Farm

If you ever need to programmatically obtain a list of web applications contained under your SharePoint Farm, here is some code that will do just that...

SPSecurity.RunWithElevatedPrivileges(delegate()
{
    SPFarm farm = SPFarm.Local;
    SPWebService service = farm.Services.GetValue("");

    foreach (SPWebApplication webApp in service.WebApplications)
    {
        // The following code will need to be changed depending on your situation
        ComboBoxItem webAppItem = new ComboBoxItem(webApp.DisplayName, webApp.Id);
        cbWebApp.Items.Add(webAppItem);
    }
});

NOTE: In this particular instance, I'm writing my list of web applications to a combo box control of a Windows application. The idea is that this combo box control will be the first of several chained combo boxes that will allow you to dive deeper into the SharePoint objects based on the items selected in the combo box controls (i.e. Web Application -> Site Collection -> Site -> Document Library -> Document).  Perhaps this my inspire some ideas of how or why this code would be useful.

Tuesday, January 15, 2013

A solution for providing a "sum" operation on a calculated field in a SharePoint view

One of our site owners recently ran into a situation in which he was trying to create a SharePoint view that would provide a sum of all values contained within a calculated field, but was not able to do so via the simple configuration process.  By "simple configuration" process, I'm referring to the typical way that you would provide a sum on a standard number or currency field which would be to place your view in edit mode, scroll down to and then expand the Totals group, locate your field, select the "Sum" operation listed in the drop down control, and save the change to your view.  Unfortunately, this isn't possible for calculated fields due to the fact that calculated fields don't show up under the Totals group.  With this in mind, a few possible solutions that would provide the requested functionality are listed as follows:

  • Use a Content Query Web Part to host the XSLT code that would generate the desired view
  • Use SharePoint Designer to modify the XSLT code of the view directly.  In SharePoint 2007, you would do this by inserting a Data View web part and modifying the XLST of that web part. 
  • Change the calculated field to a regular number or currency field, add a workflow to the list that would perform the calculations previously associated with the calculated field, and place a sum operation on the field

After a discussion with the user about the requirements for this effort as well as the various options available, we came to the conclusion that it would be possible to use a simple, one-time solution to meet the needs of his effort.  In light of this, we chose the workflow option and decided to add our workflow to the list using SharePoint Designer.  If you're interested in this solution, here are the steps we took to make this happen:

Replace the calculated field with a standard number or currency field
  1. Using your browser, open the site and navigate to the list to be modified
  2. Under List Tools, click on the List tab
  3. Click on List Settings
  4. Under Columns, locate your calculated field and click on it's link
  5. Record the formula for your calculation
  6. Click Delete to remove the column
  7. Click on Create column
  8. For Column name:, enter the name of the original calculated field that you just deleted
  9. Select either the Number or Currency radio button depending on which you require
  10. Click OK
Create and publish the calculation workflow using SharePoint Designer
  1. Open Microsoft SharePoint Designer 2010
  2. Click Open Site
  3. For Site Name:, enter the URL of the site your list is contained under
  4. Click Open
  5. Under Navigation, click on Lists and Libraries
  6. Click on the list you wish to perform the calculations on
  7. Under Workflows, click on the New... icon
  8. Add an appropriate Title and Description for you workflow
  9. Click OK
  10. Once the Workflow Designer appears, click on the Action button
  11. Under Core Actions, select Do Calculation
  12. Click on the first value link
  13. Click on the function icon
  14. For Data source:, select Current Item
  15. For Field from source:, select your first field that is part of the calculation
  16. Click OK
  17. Click on the plus link and choose the appropriate option for your calculation
  18. Click on the second value link
  19. Click on the function icon
  20. For Data source:, select Current Item
  21. For Field from source:, select your second field that is part of the calculation
  22. Click OK
  23. Click on the Action button
  24. Scroll down to List Actions and click on Set Field in Current Item
  25. Click on the field link and select the field you just created previously that replaced the original, calculated field
  26. Click on the value link
  27. Click on the function icon
  28. For Data source:, select Workflow Variables and Parameters
  29. For Field from source:, select the Variable: calc item
  30. Click OK
  31. If needed, continue adding calculation steps until the workflow is complete
  32. Click the Save button
  33. Under Navigation, click on Workflows
  34. Click on the link associated with your newly created workflow
  35. Under Start Options, remove the check from the Allow this workflow to be manually started option
  36. Place a check in both the Start workflow automatically when an item is created and Start workflow automatically when an item is changed options
  37. Click the Save button
  38. Click the Publish button
Update your view to provide a sum on the new field
  1. Using your browser, open the site and navigate to the list to be modified
  2. Under List Tools, click on the List tab
  3. Click on List Settings
  4. Under Views, locate your view and click on it's link
  5. Scroll down to and then expand the Totals group
  6. Locate your new field and select the "Sum" operation listed in the drop down control
  7. Click Save
With these steps complete, the new "calculated" field will be updated by the workflow every time a list item is created or modified.  NOTE: Users will be able to enter values into the "calculated" field; however, the workflow will ultimately override this value when the items is created or saved.  At this point, you will now have a "sum" operation on your "calculated" field.