Tuesday, 15 July 2014

How to Get the Current User's Properties Using CSOM in SharePoint 2013:

How to Get the Current User's Properties Using CSOM in SharePoint 2013:
The following are the prerequisites:

SharePoint 2013.
Visual Studio 2012.
User Profile Service application provisioned.
User profiles should be created.
Create a console application in Visual Studio 2012 using the following:

Open Visual Studio 2012 (Run as administrator).
Go to File=> New => Project.
Select Console Application in the Visual C# node from the installed templates.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.UserProfiles;

namespace UserProfileService
    class Program
        static void Main(string[] args)
            //// String Variable to store the siteURL
            string siteURL = "http://gowtham/";          

            //// To get the context of the SharePoint site to access the data
            ClientContext clientContext = new ClientContext(siteURL);

            //// PeopleManager class provides the methods for operations related to people
            PeopleManager peopleManager = new PeopleManager(clientContext);

            //// PersonProperties class is used to represent the user properties
            //// GetMyProperties method is used to get the current user's properties
            PersonProperties personProperties = peopleManager.GetMyProperties();
            clientContext.Load(personProperties, p => p.AccountName, p => p.Email, p => p.DisplayName);
            //// Display the user  properties - AccountName, Email,  DisplayName
            Console.WriteLine("Account Name: " + personProperties.AccountName);
            Console.WriteLine("Email: " + personProperties.Email);
            Console.WriteLine("Display Name: " + personProperties.DisplayName);

Hit F5. The output will be displayed in a console window.
note: please add a assembly reference in a visual studio solution explorer.
Add the following assemblies from hive 15 (C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI).
a. Microsoft.SharePoint.Client.dll
b. Microsoft.SharePoint.Client.Runtime.dll

Sunday, 13 July 2014

Deploy the wsp in sharepoint using powershell method

Now i opened the SharePoint Powershell run this script.

Adding wsp to solution Management
Add-SPSolution "C:\Users\DotNetSharePoint\Desktop\WSPName.wsp"

once we run this command on powershell we can see the wsp file in Central Admin->System Settings->Manage Form Solutions.
we can see the deployed WSP.

Deploy the Wsp to Particular web application
Install-SPSolution –Identity WSPName –WebApplication http://Testssample/ –GACDeployment

Active the Feature 

Enable-SPFeature –Identity FeatureName –url http://testsample/sites/Home

Deactive the Feature

Disable-SPFeature –Identity FeatureName –url http://testsample/sites/Home

Uninstall the Feaure
Uninstall-SPFeature FeatureName 

How to create Calculated Fields in SharePoint

  Calculated columns we can automatically generating data, adding days to a date column to calculate an expired or due date column, Number or Currency columns to get a total…
In list, I want to create field “SP2013”, in 2013 I want to show year (yyyy). Now we are going to create calculated field for SP2013.  Navigate to list settings in any custom list, click on create column. Type your Column Name “Year” and select “Calculated” column and type  formula  “"SP"& (TEXT([Created],”yyyy”))” as shown in fig below.


"SP"& (TEXT([Created],”mmmm dd, yyyy”))                                                      October 17,2012

"SP"& (TEXT([Created],”yy”))                                                                                     SP13

"SP"& (TEXT([DateTimeField],”hh:mm:ss”))                                                           SP12:00:05

"SP"& (TEXT([Created],”dddd”))                                                                               SPWednesday

"SP"& (TEXT([Created],”mmmm”))                                                                              SPOctober

Hide Ribbon control in SharePoint 2010

 The Security Trimmer control can be place around the ribbon in Master page.The PermissionString attribute value can be changed based on the requirement.And replace the code in master page and paste the below code in master page.
<SharePoint:SPSecurityTrimmedControl PermissionsString="ManagePermissions" runat="server">
   <div id="s4-ribbonrow" class="s4-pr s4-ribbonrowhidetitle">

Hiding Add New Item in SharePoint 2010

Add the below code in Content Editor/Html form web part in SharePoint 2010 and save the page.

 td.ms-addnew { display:none; } 

Creation App in SharePoint 2013

This article will hnelp you   to create a  App in SharePoint2013 step-by-step. 

Create a farm solution and SharePoint-Hosted App
Use the following procedure to create a farm solution and SharePoint-Hosted App in Visual Studio 2012:
  1. Run Visual Studio as administrator, and choose "File" -> "New" -> "Project...".
  2. In the New Project dialog box, choose ".NET Framework 4.5" from the drop-down list at the top of the dialog box.
  3. In the Templates list, expand "Office/SharePoint", choose "Apps", and then choose the "App for SharePoint 2013" template.
  4. Name the project "SiteApp", and then choose the "OK" button.
  5. In the SharePoint Customization Wizard dialog box, choose "Deploy as a farm solution" and then choose the "Finish" button.
  6. In Solution Explorer, open the shortcut menu for the SiteApp project, and expand the Pages folder and click on the default.aspx page.
  7. In the markup of the "Default.aspx" file, paste the following code between the "Main" asp:Content tags. This code defines controls and script references.
  8. HTML<div>Site Name: <inputtype="text"id="siteName"value=""/>
  9. Open the "App.js" file under the Script folder. Replace with the following code:
    function getQueryStringValue(key) {
    var returnValue = "";
    var params = document.URL.split("?")[1].split("&");
    var strParams = "";
    for (var i = 0; i < params.length; i = i + 1) {
    var singleParam = params[i].split("=");
    if (singleParam[0] === key) {
    return decodeURIComponent(singleParam[1]);
        return returnValue;
    function createSite() {
        var hostWebUrl = getQueryStringValue("SPHostUrl");
        spcontext = 
    new SP.ClientContext.get_current();
    //then use the host web URL to get a parent context -this allows us to get data from the parent    parentCtx = new SP.AppContextSite(spcontext, hostWebUrl);
        currentWeb = parentCtx.get_web();
        context.executeQueryAsync(onCreationSuccess, OnFailure);
    function onCreationSuccess() {
    "In onCreationSuccess");
    var appInstanceID = currentWeb.get_appInstanceId();
    var webCreateInfo = new SP.WebCreationInformation();
    "This site created from Javascript");
    var site = $("#siteName").val();
        webCreateInfo.set_webTemplate("COMMUNITY#0");// you can add webtemplate as per your choice    web = currentWeb.get_webs().add(webCreateInfo, false, appInstanceID);
        context.executeQueryAsync(onSuccess, OnFailure);
    function onSuccess() {
    "Web created");
    function OnFailure(sender, args) {
  10. Open the "AppManifest.xml" file and set the permission to "Site Collection as Full Control".
once you created the app please deploy and add the app in site,you can create a site in sharepoint using this app.

Hope you have liked my article.

Retrieve List Items in sharepoint list using client object model

using System;
using Microsoft.SharePoint.Client;
using SP = Microsoft.SharePoint.Client;

namespace Microsoft.SDK.SharePointServices.Samples
    class RetrieveListItems
        static void Main()
            string siteUrl = "http://MyServer/sites/MySiteCollection";

            ClientContext clientContext = new ClientContext(siteUrl);
            SP.List oList = clientContext.Web.Lists.GetByTitle("Announcements");

            CamlQuery camlQuery = new CamlQuery();
            camlQuery.ViewXml = "<View><Query><Where><Geq><FieldRef Name='ID'/>" +
                "<Value Type='Number'>10</Value></Geq></Where></Query><RowLimit>100</RowLimit></View>";
            ListItemCollection collListItem = oList.GetItems(camlQuery);



            foreach (ListItem oListItem in collListItem)
                Console.WriteLine("ID: {0} \nTitle: {1} \nBody: {2}", oListItem.Id, oListItem["Title"], oListItem["Body"]);

Create Sharepoint List Using Cleint Object model

using System;
using Microsoft.SharePoint.Client;

namespace Microsoft.SDK.SharePointServices.Samples
    class CreateList
        static void Main()
            string siteUrl = "http://MyServer/sites/MySiteCollection";

            ClientContext clientContext = new ClientContext(siteUrl);
            Web oWebsite = clientContext.Web;

            ListCreationInformation listCreationInfo = new ListCreationInformation();
            listCreationInfo.Title = "My Announcements List";
            listCreationInfo.TemplateType = (int)ListTemplateType.Announcements;

            List oList = oWebsite.Lists.Add(listCreationInfo);


Create Sites, Lists and Libraries in SharePoint 2016