Wednesday, December 23, 2015

Using SPWeb.EnsureUser in SharePoint

I faced this scenario many times and when I Googled, there are many who have faced the same. I had added an Active Directory group to the site members group. Then I asked them to log in and make requests for a particular business scenario that triggered workflows. I had a scenario that another user could make a request on behalf of another. Simply someone is asking to reset an AD account of a person who lost his password. Given that there is a need to add a new list column called 'On Behalf Of' which is a person or group column, I simply used code to create an SPUser object through C# code using the people picker value where people picker was available in the request form to select the on behalf of user. 

I got the username from the people picker comma separated values and used the following code to get the user.

SPUser onBehalfOfUser = web.AllUsers[onBehalfOfuserLoginName];

Monday, December 21, 2015

Sideloading SharePoint Add-Ins

If you are a SharePoint Add-in or App developer, you could have probably come through this issue atleast once. 

"Sideloading of apps is not enabled on this site."

Sideloading is a technique that most of the app vendors allow in order to test or debug the apps. In other words, it means deploying an app with a development tool rather than going through the correct secure procedure. Sideloading is available with all the smartphone platforms including Android. 

When you are developing a SharePoint Add-in, you need to test the Add-in prior to do a proper release. There is a default site collection template that is known as "Developer Site" which allows you to sideload add-ins from Visual Studio rather than putting it to an app catalog or online store. 

But if you attempt to deploy an add-in to another site with a different template, then you may encounter the issue which is highlighted above. Now we have two options. The preferred option is to change the deployment target to a developer site. 

Thursday, December 17, 2015

Automatic Index Management in SharePoint 2016

5,000 is a familiar number for anyone who had more than 5,000 records in a SharePoint list. List View threshold is something that many of us have faced and wanted to get rid of it by expanding. But then again we think about the best practices and the good it does. So, we often end up not increasing it, but creating some indexes on the columns. The problem is many of us did not know this can be done. Even I did not in the beginning. I am sure many of us still do not know. 

Microsoft has figured out there are many among us who do not do it and have introduced something that will make the job easy. The good thing is SharePoint can make note of every query we make and find the columns that need to be indexed.

This new feature is called Automatic Index Management. Here are some characteristics on it and how it functions.

What is Automatic Index Management?

It is a setting that is by default enabled for SharePoint lists from SharePoint 2016. It creates automatic indexes for the SharePoint lists by evaluating the queries and other concerns that matter most for improving the performances.

Tuesday, December 1, 2015

Using SPList.ItemCount vs SPList.Items.Count

Developers need to write code that doesn’t consume all the server resources, so they try to use the best API calls that require minimum resources. Many feel that when it comes to using SPList.ItemCount versus SPList.Items.Count, SPList.ItemCount is a better API call. But let’s examine this more carefully.

What are the Definitions?

The MSDN definitions for both scenarios are as follows:

SPList.ItemCount: The value of the ItemCount property includes folders within a document library, as well as files within subfolders. The value of the Count property of the SPListCollection class doesn’t include folders.

SPList.Items.Count: The Items property returns all the files in a document library, including files in subfolders, but not the folders themselves. In a document library, folders aren’t considered items.

Therefore we can conclude that SPList.Items.Count gets the number of list items in the collection, excluding folders.