hello,
In sharepoint list i need to create a view for a list and make it as default view.how?
thanks
How to create a default view programmatically
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Abhay ShankerRank #375 · 6.7K reputationPosted Nov 25, 2013, 1:15 AM EST
public void createListView()
{
SPSite site = new SPSite("http://servername/testsara");
SPWeb web = site.OpenWeb();
SPList list = web.Lists["Tasks"];
SPViewCollection allviews = list.Views;
string viewName = "Test View";
System.Collections.Specialized.StringCollection viewFields = new System.Collections.Specialized.StringCollection();
viewFields.Add("Title");
viewFields.Add("Priority");
string myquery = "
allviews.Add(viewName, viewFields, myquery, 100, true, false);
}
You can also set newly created view as default view
SPView yourView = CurrentList.Views[UserView];
yourView.DefaultView = true;
yourView.Update();
krishnakumar kuna55 reputationPosted Nov 25, 2013, 3:07 AM EST
krishnakumar kuna55 reputationPosted Nov 25, 2013, 3:08 AM EST