Monday, April 22, 2013

UserProfileApplicationNotAvailableException_Logging error within SharePoint 2013

Recently while playing around with UserProfileManager, I came across a very strange issue where I couldn’t find much help on the internet. After some researching here and there, I finally found that the issue was just a permission issue. While trying to use UserProfileManager in my code, I was passing the SPServiceCOntext object to it and while creating an object of UPM, the error I was getting was

UserProfileApplicationNotAvailableException_Logging :: UserProfileApplicationProxy.ApplicationProperties ProfilePropertyCache does not have 607c1325-164c-4da5-8bd0-e28be323a06c

The resolution of this is to assign Full Control permission to the User Profile Service in Central Administration. In my case, it was my account and as I gave it full control, it ran smoothly. Follow the screenshots for details.
Navigate to Central Administration > Application Management > Manage Service Applications and select User Profile Service

Click on Permissions

Add the account which runs the designated code.

Hope this helps someone.

Friday, April 19, 2013

Importing Active Directory profiles to SharePoint 2013

This post describes one way communication of Active Directory users to be brought into SharePoint 2013 environment.
We need an account set up for the AD profile synchronization. Let’s call it “SharePointADSync“, we need to configure a couple of things on this account in AD:

Add “Replicate Directory Changes” permission
  • On the domain controller, click Start, click Administrative Tools, and then click Active Directory Users and Computers.
  • In Active Directory Users and Computers, right-click the domain, and then click Delegate Control.
  • On the first page of the Delegation of Control Wizard, click Next.
  • In the Users or Groups page, click Add.
  • Type the name of the synchronization account, and then click OK.
  • Click Next.
  • In the Tasks to Delegate page, select Create a custom task to delegate, and then click Next.
  • On the Active Directory Object Type page, select This folder, existing objects in this folder, and creation of new objects in this folder, and then click Next.
  • On the Permissions page, in the Permissions box, select Replicate Directory Changes, and then click Next.
  • Click Finish

Follow these steps now to import AD profiles to SharePoint.

Go to Central Admin. Click Manage Service applications under Application Management.

From the list of services, click on the User Profile Service Application
Under Synchronization, click Configure Synchronization Settings

Select the “Use SharePoint Active Directory Import” radio button under Synchronization Options. Click OK to save settings. You will then be redirected to the User Profile page.
Under Synchronization, click Configure Synchronization Connections and create a new connection.

Fill in appropriate values and click Populate Containers. Once the containers are populated, check the ones you would like to import to SharePoint and save the connection. In the Account name, enter the SharePointADSync account details that we have created for this purpose. 

No you can go ahead and do a full import, which will import the selected profiles to your SharePoint.

Wednesday, April 17, 2013

Edit Top Navigation Branding within SharePoint 2013


Changing the default SharePoint branding on SharePoint 2013 sites is something which I am sure all of us would want to do. You would prefer seeing your organization name rather than SharePoint on your intranet/internet sites. I am placing a screenshot so as you know what I am talking about.






While I was looking to implement the same thing, I did a bit of research and thought the newly introduced Design manager might have something. But unfortunately it doesn’t. Finally I managed to change this using CSS. However there is one another easy peezee way of doing the same thing by using powershell script.

$webApp = Get-SPWebApplication “http://WebAppURL”
$webApp.SuiteBarBrandingElementHtml = "SharePointClick"
$webApp.Update()


Tuesday, April 9, 2013

Step by Step Installation guide for SharePoint 2013


Installing SharePoint 2013 is very simple and almost same steps as we had followed when we installed SharePoint 2010. In this post I will explain step by step installation on a Stand Alone system used for trial or development purposes.
I have already installed Windows Server 2012 in my VM so I am good to go for my SharePoint 2013 installation.
Download the ISO for SharePoint and mount it. For mounting, just right click and say Mount.
Let us install the Pre-requisites first. Follow the screenshots below for clarity.

 Check the Accept checkbox and click Next
 Sit back and wait for the pre-requisites to be installed
 Click Finish and restart your system
 Once you restart the installer will continue and finish the installation. Then its time to double click the Setup.exe and start installing SharePoint 2013. The first thing you will see is that it will ask you to enter your Product Key. Enter the key and click on Continue.
 Once again it will ask you to accept to their terms which anyways we all have to.
Select the Server type, in my case I wanted a Stand Alone as I use this for development purposes. You can select your case and say Install Now. 
By default SharePoint will be installed in your C drive, I recommend you do not change it. However if that is one of your requirement, you can do it now in the File Location tab.
 Sit back, relax and wait for the installation to finish

Installation is complete now and you can now configure your SharePoint 2013



Finally, the installation is complete and now you will be asked to create the first SharePoint 2013 site and bingo, you have installed SharePoint 2013 successfully. You can now browse to the Central Admin and create Web applications, site collections and dive into the deep SharePoint sea.

Like us on Facebook for more SharePoint 2013 updates.

Thursday, April 4, 2013

Programatically breaking inheritance and adding unique permission to List Items


Permission handling is something which makes SharePoint a favorite product within the industry. SharePoint has Permission levels in built for basic roles, however you can create your own permission levels and assign to Groups and then set those groups to access any site/library/list. Whenever a sub-site is created, it asks you if you want to inherit the permission from the parent site or want to create unique permissions. 

If you choose to inherit the permissions, it will copy the same set of permissions to the sub-site which will again be passed on to the lists/libraries you create. It may happen that for securing our content, we want to break this inheritance and want to assign unique permissions to restrict the users for certain actions and to make the content more secure. Inheritance can be broken manually using the Out of feature also and if you have a business logic in place, you can do it programmatically also. This blog post gives you code to break inheritance for items meeting certain criteria and assigning permissions to them explicitly. I am using ItemAdded() event receiver to do this. You can use it within workflow or any custom webpart as well.

SPGroup securityGroup = spWeb.SiteGroups["Security Group Name"]; 
SPRoleDefinition groupRole = spWeb.RoleDefinitions["Read"]; 

SPRoleAssignment roleAssign = new SPRoleAssignment(securityGroup); 
roleAssign.RoleDefinitionBindings.Add(groupRole); 

SPListItem listItem = spWeb.GetListItem("http://List Item URL"); 
listItem.BreakRoleInheritance(true); 
listItem.RoleAssegnments.Add(roleAssignment); 
listItem.Update();

Monday, April 1, 2013

Creating Event Recievers within Visual Studio 2010

Event receivers can be broadly seen as of two types:

Asynchronous (triggered before finishing of previous event)
          ItemAdding, ItemUpdating
Synchronous (triggered after finishing the previous event)
          ItemAdded, ItemUpdated

Follow Steps to create an event receiver with Visual Studio 2010 and SharePoint 2010 :
  • Open up Visual Studio 2010 with administrator privileges
  • Click File > New > Project
  • Under Installed templates, click SharePoint and then select Event Receiver (C# in my case). Enter the name, storage location and Solution name in the text box provided and click on OK.
    • It will then ask you to specify the site and trust level or scope of your solution. If you want to deploy it across your farm so that all web applications can make use of it, you should select Deploy as Farm Solution. However, with event receivers, it is not usual so we will select Deploy as Sandboxed solution, which means it will only be accessible to the sites where we activate this feature.
    • Now it will ask you to select the type of Event Receiver you would like to create. In our case it would be List Item Events. Then select what item should be the event source, here we will select Document Library as we want to create an item in document library and want our event receiver logic to run after that. You may want to select Picture library or a list here or as per your business scenario.

    • Now, check the events you would want to code for within your receiver. For the sake of example, I will check An Item was Added which means it will automatically create a method stub for me with ItemAdded method. Now click on Finish.


    Our development IDE is ready to use now and you can see the method stub for ItemAdded being created already.

    Copy and Paste the code below to your solution.
    using (SPWeb web = properties.OpenWeb())
    {
        //Name is a metadata column within my document library
        //Checking if the Name field is equal to Test
        if (properties.ListItem["Name"] == "Test") 
        {//If it is
            // Populating the Title field with some value
            properties.ListItem["Title"] = "Event handler works"; 
            // Updating the ListItem to incorporate the change. 
            // Necessary step, without this  the changes are not pushed to ListItem
            properties.ListItem.Update(); 
        }
    
    }
    
    
    Some more useful methods which can be used are
    //Name of the Document Library
    string DocLibraryName = properties.ListTitle.ToString();
    
    //Getting the Item ID
    int ItemID = properties.ListItem.ID;
    
    //Collection of Role Assignments - required for controlling permission to the Item
    SPRoleAssignmentCollection roleAssignment = properties.ListItem.RoleAssignments;
    

    Build the solution and deploy it. Go to your SharePoint site and activate it(if not already activated) and create any document library and create an item with Name as Test and see your event receiver in action.

    This event receiver will fire on all the document libraries within your site where you have activated the feature, if this is not the intended behaviour, use
    if(properties.ListTitle.ToString() == "DocumentLibraryName")
    
    And write all your logic within your IF block.

    For any queries please feel free to email me. If this post helped you, please share it and benefit more and more fellow SharePoint developers