About Me

My photo
a Dynamic and Energetic guy.....

Wednesday, September 24, 2008

Sharepoint --- Change the default view programatically

Hi...
I had a requirement to change the default view programatically...
I tried so many code snippets, but it didnt work...
Finally i got the treat...

SPView myNewDefaultView = myList.Views["MyNewView"];
myNewDefaultView .DefaultView = true;
myNewDefaultView .Update();
myList.Update();

its really good to set
rootWeb.AllowUnsafeUpdates = true;
before you try this...
done.......

1 comment:

Anand Bandaru said...

Good one. i searched almost everywhere to get the VIEW.UPDATE() statement right. Previously I was just updating the list after changing the view.defaultview = true.

Thanks a lot

My Masters