SharePoint Dragons

Nikander & Margriet on SharePoint

SharePoint 2013 Best Practices

The SharePoint 2013 Best Practices was updated again and is becoming more extensive: http://social.technet.microsoft.com/wiki/contents/articles/12438.sharepoint-2013-best-practices.aspx

Getting the right set of permissions when creating a custom permission level in PowerShell

Despite all its power and flexibility, developing PowerShell scripts feels like a dev experience that could be had 15 years ago. Often, we find ourselves creating prototypes in VS.NET first, before diving into the murky waters of visual PowerShell editors. Having that off our chest, suppose you’re creating a PS script that creates a new SharePoint permission level. The code is not too hard, something like:

$CustomPermissions = New-Object Microsoft.SharePoint.SPRoleDefinition
$CustomPermissions.Name = “TheName”
$CustomPermissions.Description=”A Descr”
$CustomPermissions.BasePermissions=”ViewListItems, AddListItems, EditListItems, OpenItems, ViewVersions, ManagePersonalViews, ViewFormPages, Open, ViewPages, CreateSSCSite, etc., etc.”
$RootWeb.RoleDefinitions.Add($CustomPermissions);

Now, what’s the easiest way to get to the permission mask you want? We do this:

  1. Create it first via the SharePoint UI (Site Actions > Site Settings > Site Permissions > Permission Levels).
  2. Create a C# program in Visual Studio that loops thru all permission levels until you find the one you created.
  3. Add the object holding the permission level to the QuickWatch window.
  4. Open the XML property using the XML visualizer.
  5. Copy the value of the BasePermissions attribute and use that string value in your PS script.

The C# code (run from a C# Console Application) looks like this:

using (SPSite site = new SPSite(“http://moon”))
{
  using (var web = site.OpenWeb())
  {
    foreach (SPRoleDefinition roleDef in web.RoleDefinitions)
    {
      Console.WriteLine(roleDef.Name);
    }

}

SharePoint Flavored WebLog Reader (SFWR) 1.4 is released!

We just released SFWR 1.4 at http://gallery.technet.microsoft.com/The-SharePoint-Flavored-5b03f323#content

What does it do?

“The IIS logs are an invaluable way to get to know your web application and your end users once it’s in production. Therefore, having a tool to analyze IIS logs is in invaluable asset in your bag of tricks. Especially if this tool has a certain SharePoint flavor added to it…”

What’s new?

5-2-2013 UPDATE Released SFWR V1.4

– Did some bug fixes (the slowest reports ordered by alphabet, instead of by number, duh!)

– Clarified up some reports, as there were some questions surrounding the time units in the reports. It should all be clear now.

SharePoint 2010: Problem Adding Term Sets with ‘&’ in their name

We were working on a PowerShell script that reads an XML file and uses that as the basis for adding new terms to SharePoint. Some of the term names in XML contained & which eventually gets replaced by the ampersand (&) character. Now, something strange happens, SharePoint converts this to the 65286 character (or 0xFF06 in Hex). This is an ampersand (&) character, but not the same as the normal ampersand (&) 38 character. But, PowerShell converts the ampersand (&) character to the normal 38 character, and then you’re in limbo land. What happens is this:

  1. We check if a term exists.
  2. If it’s not, we add it.
  3. We commit all changes.

Once we were committing, an error occurs stating that we were trying to add a term that already exists. Why is that happening?

  1. In PowerShell, we check for a term that contains & (= char 38). It’s not present in the SharePoint term store, there’s just the term containing & (= char 65286).
  2. We add a new term containing char 38.
  3. SharePoint converts char 38 to char 65286, but that one is already present.
  4. An error occurs.

This problem took some time to diagnose, the solution is simpler. Make sure the index name you’re using contains char 65286, instead of char 38. In PowerShell, the code looks like this:

#Please Note:
# This is a tricky piece of code, as SharePoint converts & to a special & sign (char 65286 or 0xff06 in HEX).
# Within PS, this special & sign gets converted and equals the normal & sign (char 38).
# Therefore, a normal equality test of a string in PS NEVER matches the Terms index name in SharePoint,
# because & (value 65286) is not identical to & (value 38)
#
# To solve this issue, & (38) needs to be replaced by & (65286)           

$IndexName = $TermNode.Name.Replace(([char] 38), ([char] 0xff06))
$Term = $Termsetitem.Terms[$IndexName]

We must have won the lottery, because by mistake we also included term names containing two consecutive spaces. SharePoint tries to help out by replacing them with a single space. Now this happens:

  1. We check for a term that contains double spaces.
  2. The term store only has a term with single spaces, so the new term is added.
  3. SharePoint converts double spaces to a single space, adds the term, but that one is already present.
  4. An error occurs.

We could do another replace, but decided that this is more of a configuration mistake. So, we’re not handling that one in code, but fixed the XML config file and then things worked like a charm.

The final question is this: is SharePoint right in replacing double consecutive spaces to a single one?  We decided the answer is no. Fixing term spelling makes the mechanism unpredictable and arbitrary (since SharePoint only seems to care about & and double spaces). Besides, it’s not SharePoint that has to decide on the name, it’s the term store administrator/end user who needs to decide. It reminds us of years ago. We were writing a technical design document and correcting the spelling of business terms that were used in a functional document written by the customer. At that time, we had a mentor who said: “Leave it be, you may not agree, but it’s the customer who decides on the business terms”. We thought this was a wise advise.

Cross-origin communication

The JavaScript window.postmessage seems to be just what we were looking for when looking for a mechanism for SharePoint Apps to talk to each other: https://developer.mozilla.org/en-US/docs/DOM/window.postMessage

The Super Secret Wiki Ninja Secret

Margriet’s Wiki Ninja post called “The Super Secret Wiki Ninja Secret” can be found here: http://blogs.technet.com/b/wikininjas/archive/2013/01/20/the-super-secret-wiki-ninja-secret.aspx

Top 10 SharePoint Blogs

From now on, we’re going to do the SharePoint 10 blogs differently. We’re going to do it once every 3 months and try to get more community participation. In +/- 2 weeks a Sticky Thread will appear in the SharePoint forums where people can vote on the Top 10 blogs. This voting process will be repeated quarterly. The top 10 will be placed on the popular TechNet Wiki SharePoint 2013 Best Practices page and will appear on the TechNet Wiki Ninja Blog Spot.

Working with .BLG files

When doing performance analysis, we routinely record .blg files using perfmon to inspect the various servers involved in the SharePoint farm. We were looking for a library or piece of .NET code to read such .blg files but eventually came to the conclusion that there are only two workable solutions:

$result = import-counter .\sample.blg
$result | export-counter -path .\output.csv -FileFormat csv

For more info on SharePoint related perf counters and the related get-counter cmd, check out http://gallery.technet.microsoft.com/PowerShell-script-for-59cf3f70

SharePoint 2013 Feature Overview

And another SharePoint 2013 feature comparison overview: http://www.apps4rent.com/sharepoint-2013-features-comparison.html

It’s the SharePoint Flavored Weblog Reader again!

 

We’ve released SFWR v1.3.

What is it?

“The IIS logs are an invaluable way to get to know your web application and your end users once it’s in production. Therefore, having a tool to analyze IIS logs is in invaluable asset in your bag of tricks. Especially if this tool has a certain SharePoint flavor added to it…”

What’s the update?

“Not everybody has the same IIS logging settings, that’s why SFWR uses the DLR to support this. Nevertheless, there were certain reports that threw exceptions and caused processing to halt because they expect certain data to be present (mainly bytes sent and bytes received). v1.3 uses a little Aspect Oriented Programming (AOP) to make sure all report calculation errors are handled.”

Where to  get it?

http://gallery.technet.microsoft.com/The-SharePoint-Flavored-5b03f323