How to: Programmatically remove a Field (SPField) from a view (SPView)

Author: Tobias Zimmergren


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"];

    bool allowUnsafe = SPContext.Current.Web.AllowUnsafeUpdates;

SPContext.Current.Web.AllowUnsafeUpdates = true;

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

Sign up to my newsletter!

* indicates required

About Tobias Zimmergren

Hi, I'm Tobias. I plan, architect and develop software and distributed cloud services. Nice to meet you!