Add HyperLink programmatically in WPF.

[code lang=”c”] Label linkLabel = new Label(); Run linkText = new Run(“(” + displayName+ “)”); Hyperlink link = new Hyperlink(linkText); link.NavigateUri = new Uri(“http://url”); link.RequestNavigate += new RequestNavigateEventHandler(delegate (object sender, RequestNavigateEventArgs e) { Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri)); e.Handled = true; }); linkLabel.Content = link; [/code]

Get all SharePoint site users using Client object model

[code lang=”c”] class Program { static void Main(string[] args) { using (ClientContext ctx = new ClientContext(“http://siteUrl”)) { NetworkCredential netCredentials = new NetworkCredential(“userName”, “password”); ctx.Credentials = netCredentials; try { Web web = null; web = ctx.Web; RoleAssignmentCollection assignColl; RoleAssignment roleAssign; RoleDefinitionBindingCollection bindingColl; ctx.Load(web.RoleAssignments, roles => roles.Include( r => r.Member, r => r.Member.LoginName, r => r.Member.Title, r => r.RoleDefinitionBindings )); ctx.ExecuteQuery(); assignColl […]

Get all SharePoint site users using Client object model

class Program { static void Main(string[] args) { using (ClientContext ctx = new ClientContext(“http://siteUrl”)) { NetworkCredential netCredentials = new NetworkCredential(“UserName”, “Password”); ctx.Credentials = netCredentials; try { Web web = null; web = ctx.Web; RoleAssignmentCollection assignColl; RoleAssignment roleAssign; ctx.Load(web.RoleAssignments, roles => roles.Include( r => r.Member, r => r.Member.LoginName, r => r.Member.Title )); ctx.ExecuteQuery(); assignColl = web.RoleAssignments; for (int isitePermCount = 0; […]

Add or Remove permission level to SharePoint group or user programmatically.

[code lang=”c”] Below code describes how to add/remove permission level to user programmatically using client object model. class Program { static void Main(string[] args) { using (ClientContext ctx = new ClientContext(“http://siteUrl”)) { NetworkCredential netCredentials = new NetworkCredential(“userName”, “password”); ctx.Credentials = netCredentials; try { Web web = null; web = ctx.Web; RoleAssignmentCollection assignColl; RoleAssignment roleAssign; string userOrGroup = “Administrator”; //we can […]

Determine SharePoint server version using Client object model

 Get SharePoint server version using client object model. To determine which version of SharePoint you are currently using, by client side object model Example:- [code lang=”c”] Class Program { static void Main(string[] args) { using (ClientContext ctx = new ClientContext(“siteUrl”)) { string version = string.Empty; ctx.ExecuteQuery(); version = ctx.ServerVersion.ToString(); if (version.StartsWith(“14.”)) version = “SharePoint2010”; else if (version.StartsWith(“15.”)) version = “SharePoint2013”; […]

Retain internal name of list columns while copying list from One site to another site using client object model

Internal name is a property of list fields which is read only and cannot be edited. Internal name is created according to field title while creating field. If we rename field title internal name will not be changed. If one user has created a custom column and give title=”Column” then internal name will be “Column” After renaming field title ‘Internal […]

Copy list item and keep same ID

Retain Item ID while copying item from one list to another list While copying/migrating item list item id can’t be retained ID field of list is read only field, that field cannot be edited, id field is auto increment integer value, which will be increment by one after every item was added. Procedure to retain item id (id of every […]

How to get items from a specific SharePoint List View using client object model

Below code describes how to retrieve items from sharepoint list by specific view using client side object model Add reference “Microsoft.sharepoint.client.dll” and “Microsoft.sharepoint.client.Runtime.dll”. Write Below Code. using Microsoft.SharePoint.Client; namespace ConsoleApplication {       class Program     {         static void main(string[] args)         {             using (ClientContext ctx=new ClientContext(“http://siteurl”))             {                 //Apply Credential                 ctx.Credentials […]

How to get list item version history of a custom list using Client Object Model

Below code describes how to get the list item version history of a custom list using Client Object Model Add reference “Microsoft.sharepoint.client.dll” and “Microsoft.sharepoint.client.Runtime.dll”. Write Below Code. class Program { static void Main(string[] args) { using (ClientContext ctx = new ClientContext(“SITE_URL”)) { CamlQuery camlQuery = new CamlQuery(); Web web = ctx.Web; ctx.Load(web,                     w => w.ServerRelativeUrl,                     w => w.Lists); […]