Page 6 of 7

SP Unique Permissions Script

Hello Community,

I’ve seen many cases where a quick report would be needed to view broken permissions inside a SharePoint site. I even had this case for a customer who wanted to know if users broke some permissions in their own my sites, so I’ve made a script that will be scoped to a web application, and will loop through all site collections in that web application and tell you about any broken permissions for sites, lists or libraries, items or folders, and will give it to you in a .csv file with a nice formatting!  Click here to see how it would look in the .csv file

For more info, please visit: 



Microsoft’s Virtual Academy Initiative – Know it. Prove it

Quick info for people out there .. Recently Microsoft Virtual Academy has announced the introduction of Know it Prove it program, which is dedicated for technology enthusiasts who wish to learn more about their favorite technologies. The program includes 8 categories that you can choose your favorite area from, and a link to it was added to the home page of the MVA site: .

For the moment, it seems just a challenge for yourself to be able to complete these courses, but later on, it seems it would be more than that, but it’s nice to see Microsoft has organized some learning paths for people to know where to start with their preferred technology.



Hiding Custom Web Part If Returned Data Is Empty

In this article, I will show how to hide a web part if the returned data from SharePoint list is empty.

First thing, what I use to implement the look and feel of items inside my web part is a div tag that runs at server, as the following:

<div id=”ReturnedData” runat=”server” name=”ReturnedData”/>

That’s all good, when you get items inside your query, and loop through each item, you add in your C# code: ReturnedData.InnerHTML+= …., and you format the item as you want, I know you get the idea!

Now for the fun part of hiding your web part if the items count = 0, so if the items count = 0, the div won’t have any HTML inside, right? So we can catch that in JavaScript, like the following:


function HideIfEmpty() {

var ReturnedData= document.getElementsByName(“ReturnedData”);

if (ReturnedData[0].innerHTML == “”) {

var chrome = ReturnedData[0].parentNode.parentNode.parentNode; =“none”;





That’s it, but how have we done it?

The function HideIfEmpty gets the element by the name attribute, which is ReturnedData. It contains more than one element inside, the first element contains all the innerHTML, so we get the innerHTML by searching for the first element in the array; ReturnedData[0] if equals =”” then we don’t have any data returned.

Now we need to get a reference to the web part chrome element, which is an ancestor of the div ReturnedData, so we get it by navigating up in the hierarchy three times., then hide the chrome by executing:”none”, this is how we hide elements in JavaScript.

Note the _spBodyOnLoadFunctionNames(“HideIfEmpty”) is used to execute the function once we load the page, this is how you execute JavaScript functions on page load in SharePoint.

Hope it helps someone out there.

M . D

Writing timer job against Managed Metadata Service Application

Have you ever written a timer job in SharePoint to read from or writing to a term store in Managed Metadata, you might have done so and faced the error:

The current user has insufficient permissions to perform this operation

Even if you try to run the code with SPSecurity.RunWithElevatedPrivileges(), or with your own account from Visual Studio, it will still give you the same problem.

The thing is, that the timer job runs with its own service, which is “SharePoint 2010 Timer”, see the below image.

The user running this service has to have access to the term store administrators in Central Administration, see the image below:

Once permission is given here, you will start having access from your timer job to the managed metadata term store and create your desired term sets and terms.

Object reference exception when accessing farm properties

Here is a problem I had and it took me a while to know the reason behind it, it’s when you try to add a farm property using PowerShell, like this:

Now try to get the farm properties using the following command: $, you will see the following result:

that’s great! You could get your property name and value without any problems, so now let’s try to get the farm property in code, shall we?

In visual studio type the following in your code:

String myProperty = SPFarm.Local.Properties[“MyFirstProperty”].ToString();

Baaaaaam, you will get: object reference not set to an instance of an object.

The reason is, although you can see the farm property in PowerShell when you type $, you need to write the $farm.update() command after that in order to be able to use that property and to be visible in your code.

Hope this helps someone out there.

How to use integrated scripting environment in SharePoint 2010

You know you can use SharePoint 2010 management shell for writing cmdlets for SharePoint, but you can also use the ISE(Integrated Scripting Environment) which is a host in Windows Server 2008 used to write cmdlets for PowerShell.

First, You need to activate this host by clicking on server manager, then features>> Add Features >> Windows PowerShell Integrated Scripting Environment(ISE) and click to install.

Once you have the ISE on your server. Open it. If you try to type PowerShell cmdlets for SharePoint it won’t work, you need to direct the ISE to run PowerShell commands for SharePoint.

Type the following:

Add-PSSnapIn Microsoft.SharePoint.PowerShell

Now you can write cmdlets for SharePoint.  But note if you close the ISE and open it again, this connection with SharePoint will be removed.  So you need to call this command once the ISE opens each time, so how do you automate this?

Well, ISE has a profile inside windows server 2008. So you need to find this profile and enter the command inside it so each time the ISE opens it looks to the profile and looks up the command the command to connect to SharePoint.

Type $profile inside the ISE you will get a path to your profile, Ended with .ps1  like this :


Try to type notepad $profile, this will open the profile, in case you found this error message in notepad…

you need to create a path to your profile as provided from the path given by the ISE. then create a text

A Note About Farm Administrator

A farm administrator can do anything in your SharePoint environment! and he is a member in a group called farm administrator, so let’s see who are the members of this group in SP 2010. By default there are 3 members in this group which are as the following:


1- The user the you specified in the identity of the SharePoint central administration application pool, if you open your IIS manager, and go to application pools and see the application pool that runs the central administration, you will see the account the you specified while running the SharePoint configuration wizard. this account is part of the Farm Administrators Group.


2- The local Administrator of the server that has SharePoint installed in it. but one important note i like to add. if you have Domain Controller on your server and installed SharePoint, you will notice that the local administrators group is gone. you will not find this option in your windows settings when you have domain controller installed your server.

3- As you have guessed it. The user that you used when you installed SharePoint. This user for sure will be part of Farm Administrator.


I Hope that this little note has helped you understanding the Farm Administrator group that you have been seeing all the time in SharePoint Central Administration.

Extra column in Content Query WebPart not showing

So one quick tip..  I had a requirement to add an extra field for a CQWP, and map it to display a column inside my target list, Here is a mistake that took me a while until I figured it out:

So to add a new field, we modify both ItemStyle.xsl and the .webpart file to include our new field, right?

I have my field inside my list called: SecondLocation, so in our Template inside the ItemStyle.xsl, we add this field inside a div or any other html control we may need, in order to style it, like this:

<xsl:value-of select=”@SecondLocation”/>

Now we will add this field to the webpart itself, because it’s not there by default, so we export the webpart, and add this field to the “CommonViewFields” section, what I did is like this:

<property name=”CommonViewFields” type=”string”>
SecondLocation, Text

When I tried to view the webpart, I didn’t see my field displayed, Although the internal name is right, the field is written in ItemStyle.xsl, the field is added to the .webpart file, the thing is with the formatting of the xml for the .webpart itself, instead of writing the properties for the webpart on multiple columns, you should write it all on the same column, like this:

<property name=”CommonViewFields” type=”string”>SecondLocation, Text</property>

Get manager Information for current user in InfoPath 2010

In this article, I’m going to demonstrate how to get the current user’s manager’s information.

We all know the usage of userprofileservice.asmx in InfoPath 2010 and how we can extract data for the current user using this web service. But what if we want to get information for user’s manager, like first name and last name. In this case we need to add a second data connection, this data connection is going to behave as a source to get manager information. To do this, click Data from the ribbon, then add data connection to userprofileservice.asmx and getuserprofilebyname , call it Profile Second Connection.Now we will have these 2 data connections in the data connection section in InfoPath 2010 as the following:


Add a field to the main data source call it manageraccountName, you do this by right clicking on the myFields folder in the right pane, and add a field,  and use the Profile First Connection to get the manager account name into this field, you do this by opening field’s properties, click the Fx button next to default value, click insert Field or Group, Change the data source to Profile First Connection, Expand the data fields until you reach the value field, click one click on the value, and click filter data, in the filter data popup, click add, change the left dropdown list to “Select a field or group”, in the select field or group popup choose the “Name” field, click OK, in the right dropdown list write “Manager”, and click OK for everything.

Second step is to put action on this manager field, this action is going to set the field value for the Profile Second Connection to its value. It’s a complex process but follow my steps literally.

Click on the manager account name field, click manage rules, add a new rule and make an action inside it, the action is of type Set a Field’s value, for the field click on the button to choose the field, from the data connection drop down list as in the following picture:

choose the Profile Second Connection, Expand the queryFields and the group below it, and choose AccountName, Click OK, see the below picture:

In the Value field, click the Fx, click insert field or group, and choose current field (manageraccountName).

Now that you have set the value for the accountname in the Profile Second Connection to the managerAccountName, do the following steps:

1- Add new field to main data source,  called managerFirstName.

2- In the data source, change the data connection to Profile Second Connection, Expand the queryFields, then the group under it, and click AccountName, then click manage rules, Add action rule.

3-The first action will Query the Profile Second Connection,

4-The second action will set the field managerFirstName, to the value of the Profile Second Connection value where property name = FirstName, as we always do with the current user when we get his information.

See the following 3 Screenshots:

Select managerFirstName from the set field’s value wizard:

Choose the second data connection for the value of the field, click value, then click filter data,

In the filter data, choose the Name from the wizard, and type FirstName, this will get the manager’s first name.

Hope this helps people out there.

Mohamed Derhalli.

Updated: Added Screenshots as requested in the comments.

IFilter For PDF Files

We know that indexing in SharePoint doesn’t index PDF files. because PDF Files are not products for Microsoft. SharePoint only searches documents that there is an Ifilter released by Microsoft for them such as : .docx, .xlsx, .one

So we now know that .pdf is not supported by default in SharePoint. So we need to install the Ifilter for pdf on our server.

Once you download it, make the setup and then IISRESET.

So we have the Ifilter installed on our server, now we need to tell SharePoint to start indexing pdf files.

Open Central Administration >> Application Management >> Manage Service Applications

Then Choose Search Service Application. At the left navigation you will find a link called “File Types” under crawling category. which means the file types that are going to be indexed by SharePoint, click it.. You will see a page with all file types that are going to be indexed.

Click New File Type, and enter PDF.

Now SharePoint is going to index your PDF files. Note that when SharePoint searches for a word document it will view the word icon beside the documents. But when searching for PDF document it will not view the PDF icon beside the results because PDF icon is not listed in list of icons that SharePoint recognize.

So we have one more thing to do to make this perfect!

We’ll add PDF icon, you can get this one. 

Name it pdfimage.jpg and save in 14TemplateImages

Now navigate to 14TemplateXML and search for a document called DOCICON.XML, open it in a text editor tool, you are going to see a tag called <ByExtension>. This tag contains records for icons supported by SharePoint like ppt for Microsoft PowerPoint and key name one for Microsoft OneNote. We will have to add a key for PDF files, so just add this record <Mapping Key= “pdf” Value= “pdfimage.jpg”/> (you can see that this file looks up images from the images folder). save the file. Now try to search for a document with PDF type, you will find that the icon appears.

Have a nice search ! 🙂