Monday 22 December 2014

  1. Creating a List from Custom List Template in SharePoint 2013


  2. using(ClientContext ctx = new ClientContext("http://mysite/"))  
  3. {  
  4.       ListTemplateCollection ltc = ctx.Web.ListTemplates;  
  5.       ctx.Load(ltc);  
  6.       ctx.ExecuteQuery();  
  7.       ListTemplate listTemplate=null;  
  8.       foreach (ListTemplate lT in ltc)  
  9.       {  
  10.             if(lt.Name.Equals("My Custom List Template"))  
  11.             {  
  12.                   listTemplate = lT;  
  13.             }  
  14.       }  
  15.       ListCreationInformation lc = new ListCreationInformation();  
  16.       lc.Title = "EmployeeList";  
  17.       lc.TemplateType = listTemplate.ListTemplateTypeKind;  
  18.       lc.Description = "This holds employee information";  
  19.       List newList = ctx.Web.Lists.Add(lc);  
  20.       ctx.ExecuteQuery();  
  21. }  

Programmatically Apply the filter to SharePoint List Default View

  1. string tempQuery= "<Where><Eq><FieldRef  Name=\"Title\"/>"+  
  2.          "<Value Type=\"Text\">xyz</Value></Eq></Where>;  
  3.   
  4.   
  5. SPList listView= oWeb.Lists[listName];  
  6.   
  7.   
  8.   
  9. for(int i = 0; i < listView.Views.Count; i++)  
  10. {  
  11.   
  12.     //Get the view   
  13.     SPView view = listViewActual.Views[i];  
  14.   
  15.     if(view.DefaultView)  
  16.     {  
  17.        oWeb.AllowUnsafeUpdates = true;  
  18.                         
  19.         view.Query = tempQuery;  
  20.         view.Update();  
  21.         oWeb.AllowUnsafeUpdates = false;  
  22.        
  23.     }  
  24. }  

No comments:

Post a Comment