Posts

Showing posts from April, 2017

Build a basic WCF Service and Call it with different endpoints

Image
Problem Definition Build a basic WCF Service, consume it in a client and demonstrate the WCF calls using different Http bindings: BasicHttpBinding WsHttpBinding WsDualHttpBinding Service Contract  [ServiceContract(ProtectionLevel = ProtectionLevel.None)]  public interface IService1  {         [OperationContract]         string GetData(int value);       } Service Contract Implementation  public class Service1 : IService1  {         public string GetData(int value)         {             return string.Format("You entered: {0}", value);         } } Service Model Configuration Client Side Implementation class Program {         static void Main(string[] args)         {         ...

SharePoint - Client Side Object Model(CSOM) - Managed - Update Item in an Existing List

Image
Problem Definition Update Item data in an Existing List using Managed Code and Client Side Object Model(CSOM) for SharePoint 2013. Prerequisites Please Visit Code Example /// <summary> /// Update Item with data to list /// </summary> /// <param name="title"></param> /// <param name="itemssWithFieldValuePairs">Pass a Comma Separated combination of field title and Value and separate the combo with a semicolon /// Eg: "Title,Test Entry;FirstName,TestFName1;LastName,TestLName1" /// </param> public static void UpdateItemToList(string title, string itemssWithFieldValuePairs) {             try             {                 //var spContext = new ClientContext("http://<your server>/<site>/");                 using (spContext)           ...

SharePoint - Client Side Object Model(CSOM) - Managed - Add Item to an Existing List

Image
Problem Definition Add Item with data to Existing List using Managed Code and Client Side Object Model(CSOM) for SharePoint 2013. Prerequisites Please Visit Code Example  /// <summary>  /// Add Item with data to list  /// </summary>  /// <param name="title"></param>  /// <param name="itemssWithFieldValuePairs">Pass a Comma Separated combination of field title and Value and separate the combo with a semicolon  /// Eg: "Title,Test Entry;FirstName,TestFName;LastName,TestLName"  /// </param>  public static void AddItemToList(string title, string itemssWithFieldValuePairs)  {             try             {                 //var spContext = new ClientContext("http://<your server>/<site>/");                 using (spC...

SharePoint - Client Side Object Model(CSOM) - Managed - Add Fields to an Existing List

Image
Problem Definition Add Fields to Existing List using Managed Code and Client Side Object Model(CSOM) for SharePoint 2013. Prerequisites Please Visit Code Example  /// <summary>  /// Add fields to an existing list  /// </summary>  /// <param name="title"></param>  /// <param name="fieldsWithTypes">Pass if Comma Separated combination of field and type and separate the combo with a semicolon  /// Eg: "FirstName,Text;Created,Date"  /// </param>  public static void AddFieldsToExistingList(string title, string fieldsWithTypes)  {             try             {                 //var spContext = new ClientContext("http://<your server>/<site>/");                 using (spContext)            ...

SharePoint - Client Side Object Model(CSOM) - Managed - Create a List using Generic List Template - With ExceptionHandlingScope Implementation

Image
Problem Definition Create a list form Generic Template using Managed Code and Client Side Object Model(CSOM) for SharePoint 2013. What will happen if there is an error say list already exists. Couple of ways to get around that: Check if list already exists and do not attempt to create the list. There is a flaw that can be corrected; checking the list and then creating the list will be two server calls and this can be corrected using the second approach. This approach is using ExceptionHandlingScope, this is very helpful because this works exactly like "try catch finally". When your request enters the scope your request is already on the server and rest of the code will execute on the server as one request. Prerequisites Please Visit Code Example  /// <summary> /// Create a List from Generic List Template with ExceptionScope /// </summary> /// <param name="title">Title of the List</param> /// <param name=...

SharePoint - Client Side Object Model(CSOM) - Managed - Create a List using Generic List Template

Image
Problem Definition Create a list form Generic Template using Managed Code and Client Side Object Model(CSOM) for SharePoint 2013. Prerequisites Please Visit Code Example /// <summary> /// Create a List from Generic List Template /// </summary> /// <param name="title">Title of the List</param> /// <param name="desccription">Description about the list</param> public static void CreateAList(string title,string desccription) {             try             {                 //var spContext = new ClientContext("http://<your server>/<site>/");                 using (spContext)                 {                     // Client side SP Web Conext           ...

SharePoint - Client Side Object Model(CSOM) - Managed - Get Lists that are not hidden and have Item count more than 0 - LINQ Syntax

Problem Definition Retrieve all Lists in a SharePoint site that are not hidden and contain some items using Managed Code and Client Side Object Model(CSOM) for SharePoint 2013. Prerequisites Please Visit Code Sample /// <summary> /// Print lists titles /// </summary> /// <param name="listTitle"> List Title </param> public static void GetAllLists_LinqSyntax() {             //var spContext = new ClientContext("http://<your server>/<site>/");             using (spContext)             {                 // Client side SP Web Conext                 var web = spContext.Web;                 // Initilize web and load web object with title and description(Helps to improve performance)         ...

SharePoint - Client Side Object Model(CSOM) - Managed - Get All Non-System Fields Data

Image
Problem Definition Retrieve List Items details using Managed Code and Client Side Object Model(CSOM) for SharePoint 2013. If you try to write generic to get the user only fields it breaks due to some system fields that do not have any data and are not initialized. Prerequisites Please Visit Solution Present solution uses a list of Internal names that are system names except ID and Title. List is present here . In case link gets removed I will be passing the list int code example section. Special List sytemFieldsTitles List<string> systemFieldsTitles = new List<string>() {               "ContentTypeId",     "_ModerationComments",     "File_x0020_Type",     "ContentType",     "Modified",     "Created",     "Author",     "Editor",     "_HasCopyDestinations",     "_CopySource",     "owshiddenversion",   ...

SharePoint - Client Side Object Model(CSOM) - Managed - Get Items Summary

Image
Problem Definition Retrieve List Items summary using Managed Code and Client Side Object Model(CSOM) for SharePoint 2013. Prerequisites Please Visit Code Example /// <summary> /// Print list Items with Summary such as ID, Title and Attachments /// </summary> /// <param name="listTitle"> List Title </param> public static void GetItems(string listTitle) {             //var spContext = new ClientContext("http://<your server>/<site>/");             using (spContext)             {                 // Client side SP Web Conext                 var web = spContext.Web;                 // Initilize web and load web object                 spContext.Load(web);     ...

SharePoint - Client Side Object Model(CSOM) - Managed - Get List Fields

Image
Problem Definition Retrieve List fields with details using Managed Code and Client Side Object Model(CSOM) for SharePoint 2013. Prerequisites Please Visit Code Example /// <summary> /// Print list field names /// </summary> /// <param name="listTitle"> List Title </param> public static void GetFields(string listTitle) {             //var spContext = new ClientContext("http://<your server>/<site>/");             using (spContext)             {                 // Client side SP Web Conext                 var webContext = spContext.Web;                 // Initilize web and load web object                 spContext.Load(webContext);             ...