Hi All,
May times we need to create view dynamically and then add that created view to the List.
Here is a simple way to accomplish this task.
First make a StringCollection object.
System.Collections.Specialized.StringCollection viewFields = new System.Collections.Specialized.StringCollection();
then add Fields from list in the StringCollection object.
For example you want to create a new view with this 4 fields from list then,
viewFields.Add("LinkTitle");
viewFields.Add("Project_x0020_Type");
viewFields.Add("Job_x0020_Number");
viewFields.Add("Legacy_x0020_Job_x0020_Number");
String strQuery = "{Your CAML Query}";
This Query is for fetching all records where Title column is not blank. you can customize this query accordig to your requirement.
objTaskList.Views.Add("ViewName", viewFields, strQuery, 10000, false, true);
//to make just crteated view as default view
objTaskList.Views["ViewName"].DefaultView = true;
objTaskList.Update();
That's it. your job is done.
SharePoint Kings,Technosavvy guys hunting SharePoint Challenges... SharePoint 2013, SharePoint 2010, MOSS 2007, Windows Workflow Foundation, Project Server and Other Related Technologies.
Subscribe to:
Post Comments (Atom)
Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to sharepointkings@gmail.com with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!
If anyone would like to have their advertisement posted on this blog, please send us the requirement details to sharepointkings@gmail.com
No comments:
Post a Comment