Tuesday, October 8, 2013

jMeter 2.9 & SharePoint 2010

Intro:
So I was tasked to find the cheapest way to apply load onto a SharePoint environment. Found jMeter which lots of people raved about.

My sample SharePoint environment is:
Windows 2012 Standard
SharePoint 2013
JMeter 2.9

Symptoms/Issue:
So I created a simple load test to hit the default page of my site collection but all I got were 401s.
Response code: 401
Response message: Unauthorized
HTTP/1.1 401 Unauthorized

How to create a basic page request in JMeter for SharePoint:
  1. Download Java Runtime Environment: http://www.java.com/en/download/index.jsp
  2. Download JMeter: https://jmeter.apache.org/download_jmeter.cgi
  3. Extract JMeter.
  4. Run jmeter.bat from the bin folder.
  5. Right click Test Plan > Add > Threads (User) > Thread Group
  6. Right click on "Thread Group" > Add > Sampler > HTTP Request
  7. In the new HTTP Request you just added:
  8. Server Name or IP: uri of your site collection (without the http(s)). For example if the landing page of my site collection is: http://spdev/Pages/Default.aspx. You would just have spdev in this field.
  9. Port Number: can be left blank if using port 80.
  10. Implementation: Java <- this is the step I had to change to get this whole thing to work for me.
  11. Path: in this example I put /Pages/Default.aspx
  12. Right click on "Thread Group" > Add > View Results in Table (or View Results Tree).
  13. Now click: Run > Start (or Ctrl + R)


 

Sunday, October 6, 2013

SharePoint 2013: CSOM List Permissions in C#

Intro: I'm building a SharePoint 2013 provided hosted app. I had a requirement to retrieve permissions for the current user to a particular list. I want to enable/disable a checkbox depending on their ability to add/edit items in a particular SharePoint list. So I search around and find this:
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.list.effectivebasepermissions.aspx
Unfortunately there's no sample in the above article and aren't any examples of how to use it anywhere on the web.

Issue: The EffectiveBasePermissions isn't loaded unless you specifically ask for it. This is the CSOM way.

Solution:
using (var clientContext = new ClientContext(hostWeb))
{
    Site site = clientContext.Site;
    clientContext.Load(site);
    clientContext.ExecuteQuery();

    Web web = site.OpenWeb("Name of spweb");
    clientContext.Load(web);
    clientContext.ExecuteQuery();

    List list = web.Lists.GetByTitle("Name of List");
    clientContext.Load(list, l => l.EffectiveBasePermissions); 
    clientContext.ExecuteQuery();

    bool myAddPermission = list.EffectiveBasePermissions.Has(PermissionKind.AddListItems);
    bool myEditPermission = list.EffectiveBasePermissions.Has(PermissionKind.EditListItems);
}

The code above will more than likely get the permission of the IIS App pool running your app. You may need to change the credentials in which the clientContext is running:
clientContext.Credentials = new NetworkCredential();

Explanation:
When writing server side code we can get all the data for the Web or list. Because we can afford to. But when we use CSOM we want to minimise the amount of data going back and forth. So the clientContext won't have the "EffectiveBasePermissions" unless you tell it to.