Looking for something?

Author: Tobias Zimmergren
URL: http://www.zimmergren.net


This is yet another very simple example of a question I’ve been getting over and over the past couple of months through comments and emails – instead of answering it each time in the mail, I’m simply shooting it out here.

Deleting a Field from a View programmatically

Alright, here’s a good starting point for you to check out if you simply want to remove a field from the view. Simple as that.

SPList list = SPContext.Current.Web.Lists["MyAwesomeList"]; SPView view = list.Views["MyView"]; 

if(view.ViewFields.Exists("MyField")) {     bool allowUnsafe = SPContext.Current.Web.AllowUnsafeUpdates; 

    SPContext.Current.Web.AllowUnsafeUpdates = true;     view.ViewFields.Delete("MyField");     view.Update(); 

    SPContext.Current.Web.AllowUnsafeUpdates = allowUnsafe; }


The aforementioned code is all there’s to it in order for you to get started.
Simple, quick, effective!

Technorati Tags: SPField,SPView,SharePoint,Development

0 Comments 18 April 2009
Tobias Zimmergren

Tobias Zimmergren

Hi, I'm Tobias. I am a Microsoft MVP for SharePoint and I use this site to share my thoughts on tech with you on topics like SharePoint, Office 365, Azure and general web development.

  Malmö, Sweden

Related Post

Comments powered by Disqus