Tuesday, May 27, 2008

How to change default view of any list?

Hi All,

May times we need to make our own view and want to make that view as default view. So here we need to change AllItems View to your own created view.

Here is a simple way to do this.

SPWeb objWeb = {current_web};
SPList objTaskList = objWeb.Lists["Tasks"];
objWeb.AllowUnsafeUpdates = true;

objTaskList.Views["MyViewName"].DefaultView = true;
objTaskList.Update();

objWeb.AllowUnsafeUpdates = false;

That's it. Now you have your vreated view as default view.

2 comments:

Ilya said...

you should rather update view, not the list

Parth Patel said...

we are setting default view of the list so we have to update the list




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