Steps

  • Open Visual Studio in your system
  • Select Console Applciation template and give as name .
  • Add a Microsoft.Cleint Assembly refrence file in right side refrence tab in visual studio.
  • Replace Program.cs with the source c
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Microsoft.SharePoint.Client;
  7. namespace CSOMCodeSamples
  8. namespace CSOMCodeSamples
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14. // ClientContext - Get the context for the SharePoint Site
  15. ClientContext clientContext = new ClientContext("http://gauti.sharepoint.com/sites/sp1/");
  16. // Get the SharePoint web
  17. Web web = clientContext.Web;
  18. List list = web.Lists.GetByTitle("CustomList");
  19. // Get all the view
  20. for the custom list
  21. ViewCollection viewColl = list.Views;
  22. // Specify the columns that should be displayed
  23. string[] viewFields = {"Column1"};
  24. // Specifies the properties used to create a new list view
  25. ViewCreationInformation creationInfo = new ViewCreationInformation();
  26. creationInfo.Title = "GVRNewView";
  27. creationInfo.RowLimit = 50;
  28. creationInfo.ViewFields = viewFields;
  29. creationInfo.ViewTypeKind = ViewType.None;
  30. creationInfo.SetAsDefaultView = true;
  31. viewColl.Add(creationInfo);
  32. clientContext.ExecuteQuery();
  33. }
  34. }
  35. }

Hit F5 and check the output.

Thanks for reading my blogs.