Wednesday, February 10, 2016

How to retrieve user profile picture from user's My Site using SharePoint REST API

Social networking sites, personalization aesthetics and increased user interactions and expectations has changed the way website and portals are developed. 

One of the requirement often comes to SharePoint developers is to show user's profile picture on site/portal's home page or preferably in the site's header. SharePoint stores user related information in user's My Site but fetching the information from My Site and displaying it on other portal's pages could be a challenge. 

SharePoint REST API allows us to easily fetch all user profile related information and display it anywhere we want in the sharepoint portal. 

Below code snippet fetches the user's profile pic URL from user profile properties and assign it to a hyperlink tag on the page.

html to display profile pic as a background of a hyperlink.

Profile.js Javascript code to fetch profile pic url using Rest API and JQuery.

Monday, February 1, 2016

Programatically assign value to a 'Hyperlink or Picture Type' column in a SharePoint 2016 List

Recently I had a requirement to collect publishing pages URLs in a SharePoint 2016 List. Adding an item in a list is straight forward and that's probably the first development task every SharePoint developer does.

But I was not able to find enough resources on adding a 'HyperLink or Picture Type' column in an SPList.

Below is the code snippet to assign value to a hyper link column.

Hyper link column expects value in <ABSOLUTE URL>, <TITLE> format.

Important thing to note here is that hyperlink should always start with 'http://'. If you try to assign a relative URL or a URL which starts with 'www', you will always get SPFieldValidationException.

Hope it will help.



Saturday, January 16, 2016

How to install SharePoint 2016 (Single-Server Farm) on VirtualBox VM

In my previous article, I explained how to install Windows Server 2012 on VirtualBox VM. In this article, I will explain the process of installing SharePoint 2016 (Single-Server Farm) on VirtualBox VM and creating your first SharePoint 2016 application. 

Refer to my previous article for download links for SQL Server 2012 SP1 and SharePoint 2016 Beta 2 trial versions.

Below is the summary of SharePoint 2016 installation process. 

1. Add 'Active Directory Domain Services' Role to the server and promote the server as Domain Controller. 

2. Install SQL Server 2012 SP1.

3. Install SharePoint 2016 Prerequisites on the server. 

4. Install SharePoint 2016 Beta 2 on the server

5. Run the SharePoint 2016 Products Configuration Wizard. 

6. Configure SharePoint Farm

1. Add 'Active Directory Domain Services' Role to the Server and Promote the server as 'Domain Controller'.


1- Open Control Panel > Programs and Features > Turn Windows Features On and Off > Add Roles and Features > Click 'Next' from the Prompt Window and opt for 'Role based and Feature Based Installation. 

2. Select the Local Server from next Window and click 'Next'. 

3. Select 'Active Directory Domain Services' from next window. Setup will prompt for dependent Feature those are required for Active Directory Domain Services installation. Click on 'Add Features'. 


4. After Clicking 'Add Features' from previous window, installation will begin. Click 'Close' once the installation is completed. 



6. Now that the Active Directory domain services are installed, we need to promote the server as Domain Controller and create a Domain. Click on the warning sign appearing on the main Server Manager Window. A popup will appear. From the popup, click on 'Promote this server to a domain controller' link. 



7. Active Directory Domain Services Configuration Wizard will start. Select 'Add a new forest' option, give your root domain a domain name and click Next.



8.  On the next window provide the password for 'Directory Services Restore Mode' and click Next.


9. Click on the Install button and wait for the installation to complete. 


You need to restart the server once domain controller is setup. After restart, you will see your domain name prefix with you local admin account. (DEV\Administrator). 

2. Install SQL Server 2012 SP1


I assume you already know how to install SQL Server 2012. Run the SQL Server 2012 Wizard and install the server. Refer this article if you need any help. 

Also note that since we are setting up only virtual environment for development purpose, creating separate service accounts for different SharePoint and SQL services is beyond the scope of the article. We will only use default Local Administrator account. 


3. Install SharePoint 2016 Prerequisites


(Note that you need to have internet access on your VM to download prerequisites software).


1- Mount the SharePoint 2016 ISO file to the VM. Double click on the drive to start the SharePoint 2016 setup (Alternately you can open the drive and run default.exe or setup.exe). 

2. SharePoint 2016 installation wizard will start.






3. From the SharePoint 2016 setup wizard, under 'Install' click on 'Install the software prerequisites'. 
  

4. Click Next from the welcome window. 


5. Once the Application Server and Web Server Roles are are configured, setup will prompt to restart the Server. Restart your VM.  


6. After restart, setup will continue installation. Once the installation is successfully completed, click Finish button. 


4. Install SharePoint 2016 Beta 2


here is the main part. 


1. Run the SharePoint 2016 installation media and click on 'Install SharePoint Server' link from the installation dialog. SharePoint 2016 setup Wizard will start. 




2. Enter the SharePoint 2016 Trial Beta 2 Version Product Key NQGJR-63HC8-XCRQH-MYVCH-3J3QR and click continue. 

If this trial key does not work, please refer 'Install Instructions' section of Microsoft SharePoint 2016 Beta 2 trail version download page to get latest key. 


3. Accept the Microsoft Software License Term and click Continue. 


4. From next window, If you want to change default installation path click Browse and provide location otherwise leave default installation path and click 'Install Now'.  


5. Installation will start. 



6. Once the SharePoint 2016 Installation is finished, setup will auto select 'Run the SharePoint Products Configuration Wizard now' option. Leave this option selected and click 'Close'.



5. Run the SharePoint 2016 Product and Configuration Wizard. 


1. From the SharePoint Products Welcome window click Next. 



2. Select 'Create a new server farm' option and click Next. 



3. Provide the database server name. If database is installed on the same VM, you can just enter dot which mean local server. You can also enter local or remove database server name. 


Leave the Database name as SharePoint_Config. This will be the SharePoint central admin configuration database.


Provide the Username and Password to connect to the database and click Next. 




4. Enter the SharePoint Farm Passphrase and click Next. This Passphrase is required to connect with the Farm while adding a new server.  




5. Select the Role of the Server. Since we are setting up Single Server Farm, select 'Single-Server Farm' from this option and click Next. 





6. From Next window, specify SharePoint Central Administration Web App port number and click Next. I suggest you to keep the default port. 




7. SharePoint Product configuration will start. 




8. Once configuration is completed, copy the central administration URL and click Finished.  




6. Configure SharePoint Farm

1. Open a new browser and hit SharePoint 2016 Central Administration URL. 

SharePoint Farm configuration will start. Click on 'Start the Wizard' button.


2. From the Service Application and Services screen, leave the default option selected and click Next. 




3. SharePoint will configure the SharePoint Farm Level Applications and Services. 





 4. Once Farm Level Application and Service are successfully provisioned, you will receive the Farm Configuration completion message on the screen. scroll down and click on Finish. 





Now you can go to central admin and Create your first SharePoint 2016 web application. 


Congratulations, You have successfully installed and configured SharePoint 2016 !!

Creating Windows Server 2012 R2 VirtualBox VM for SharePoint 2016.


Microsoft SharePoint Server 2016 2 Beta 2 version was released in Nov 2015.

I decided to create the VM to explore SharePoint 2016 new features specially SharePoint 2016 Hybrid Cloud based infrastructure, Improved user experience and compliance and reporting.

In this blog I will talk about how I created the VirtualBox VM environment and how to install the Windows Server 2012 R2 on VirtualBox VM.

I decided to go for Oracle VM VirtualBox Manager simply because its lightweight and supports all different image formats (VHD/VHDX, VDI, VMDK etc). Find more details about Oracle VM VirtualBox Manager image format support here.

To setup this virtual environment you need to have at least 16GB of RAM and Core i7 processor on your host machine. I am using "New Dell XPS 15" with Quad Core 6th Gen Core i7 Processor, 16 GB RAM, 512 GB SSD Drive and touch screen display.

Once VirtualBox Manager (or HyperV, Virtual PC or WMware Workstation) is downloaded and installed. you need to download Windows Server 2012 R2, SQL Server 2014 SP1 and SharePoint Server 2016 Beta 2 ISO files.

You can download 180 Days trial version of Windows Server 2012 and SQL Server 2014 from TechNet Evaluation Center. Find the download links below.

1- Download Windows Server 2012 R2 180 days trial version here.

2- Download SQL Server 2014 SP1 180 days trial version here.

3- To download SharePoint 2016 Beta 2 trial version click here.

Follow below steps to create new VirtualBox Server VM, boot the VM from Windows Server 2012 ISO file and install the windows server.

1- Open VirtualBox and click on 'New' from top ribbon. Give your VM a name and select Version as Windows Server 2012 and click Next.


2. From next screen allocate at least 10240MB (10GB) of memory to your VM.



3. From next screen select 'Create a virtual hard disk now' and select 'Çreate'.


4. Once your VM is created, it will be available in left Pan. Right click on VM and select 'Start'. Once started it will show a 'No bootable disk error' message.

5. You need to mount Windows Server 2012 ISO image file to your VM. For that click on Devices > Optical Drives  and Choose Disk Image. Once ISO file is mounted, restart the VM.




6. Once VM is restarted, Windows Server 2012 installation will begin. Complete the Windows Server 2012 installation and get ready to configure the environment for SharePoint 2016 installation.



In my next article, I will write on configuring Windows Server 2012 R2 for SharePoint installation and then installing the SharePoint 2016 on the server.

Tuesday, June 11, 2013

Create fly-out behavior for your Current Navigation menu of SharePoint 2010 Publishing Sites.

One of the first thing SharePoint branding process involves is 'Creating a 'fly-out menu'. Steps are easy and involve basic understanding of asp.net markup and css.

Step: 01 - Copy nightandday.master and rename the copied file to my_nightandday.master.

Step: 02 - Edit the my_nightandday.master and search for <SharePoint:AspMenu ID="CurrentNav".
Change the field StaticDisplayLevels to 1 and MaximumDynamicDisplayLevels to 2

Your Current Navigation control's markup should look like this

<SharePoint:AspMenu
               ID="CurrentNav"
               runat="server"
               EnableViewState="false"
               DataSourceID="SiteMapDS"
               UseSeparateCSS="true"
               UseSimpleRendering="true"
               Orientation="Vertical"
               StaticDisplayLevels="1"
               MaximumDynamicDisplayLevels="2"
               CssClass="nightanday-menu" SkipLinkText="<%$Resources:cms,masterpages_skiplinktext%>"/>


Step: 03 - Register your custom css file in your custom master page. In my case its style.css. Below is the markup to register a custom css file in master page.

<SharePoint:CssRegistration runat="server" name= "<%$SPUrl:~SiteCollection/Style Library/MY_STYLE/style.css%>" After="corev4.css"></SharePoint:CssRegistration>

Step: 04 - Place below css classes in your custom style.csss

.nightanday-menu
{
background-color: #CFD69C !important;
border-top: 1px solid green !important;
border-left: 1px solid green !important;
border-right: 1px solid green !important;
}

.menu-item
{
border-bottom: 1px solid green !important;
}

.dynamic .menu-item
{
background-color: #CFD69C !important;
border: 1px solid green !important;
font-size: 10pt !important;
color: #676767 !important;
font-weight: normal !important;
}

Step: 05 - Go to Site  Settings  > Master Page and select my_nightandday.master page to your publishing pages. Click on save.

DONE ! Your left navigation menu is now having a cool fly-out behavior.







Tuesday, May 21, 2013

Integrating with External SQL Database through SharePoint 2010 Business Data Connectivity Services


One of the features of SharePoint is connecting with External Data like SQL, Oracle, Siebel, SAP etc. SharePoint provides two ways to do so. First one is an easier, code less way through SharePoint Designer which provides basic CRUD operations on external data. Second way is by developing a Business Data Connectivity Model through Visual Studio which enables us to write complex business logic.  
First, let’s explore how to connect with external data through SharePoint Designer.

consider, we have a custom table named Orders in our SQL Server 2008 DB (TestDB).

















Open the SharePoint Designer and click on Open Site












A dialog will appear which will allow you to select your SharePoint Site. In my case, I have a SharePoint site at http://homestation/.
Select the site and click Open. 



SharePoint Designer will open the site for you. On the left hand side under Site Objects, click on External Content Types













Click on External Content Type ribbon button from the top.  













Click on Add Connection button to specify a new external data source connection.













A dialog will appear allowing you to select the Data Source Type. Select SQL Server as Data Source as we are going to connect with SQL Server 2008.













Specify your SQL Server Database Server and Database Name. In my case, its HomeStation and TestDB respectively.













Click on Ok button. Designer will populate all DB Objects for you to select in Data Source Explorer pane.













Right click on Orders table and then click Create All Operation from the menu.


A dialog will appear which will allow us to create basic Create, Read Item, Update, Delete and Read List functions.













After clicking next Paremeters Configuration dialog will appear. Select each field one by one and click on Show in Picker from the Properties panel.













After clicking Next, Filter Parameters Configuration dialog will appear. Filters are important performance factor to consider when we handle large volume of external data.
For now lets skip this step and click Finish.













Click on Save button. SharePoint Designer will take some time to save the changes.  













Click on Create Lists & Forms ribbon button. A Dialog will appear as below. Provide the List Name as Orders and click OK button.













Navigate to All Site Content page of your SharePoint site. SQL table Orders will be available for you as a Custom List (Orders).














Click on Orders List. You can see the data in the list populating from external SQL Orders table.

Add a New Item in the list and provide details.














Go to SQL Server and refresh the Orders Table. You can see the Item inserted from SharePoint Orders List is available in the table. Similarly you can perform Update and Delete actions on the list and changes will take effect directly on the table.

















SharePoint Designer is a quick and easy way to explore SharePoint Business Data Connectivity features but in real world scenarios we have more complex logic.

In my next blog, I will explore Business Data Connectivity Model through Visual Studio which enables us to write custom business logic while integrating with external data.