I have created a SharePoint feature where I have added a list named "Employees".

I have added a Content Type "Employee" and added to it some columns like "Vacation Days Taken", "Vacation Days Earned"... I added also a calculated column "Vacation Days Left" which is the difference between the first two columns.

In the Feature Activated event receiver I have created a view where I added all the "Employee" content type columns.

SPViewCollection allviews = employees.Views;
string viewName = "Employees View";
System.Collections.Specialized.StringCollection viewFields = new System.Collections.Specialized.StringCollection();
viewFields.Add("Vacation Days Earned");
viewFields.Add("Vacation Days Taken");
viewFields.Add("Vacation Days Left");
viewFields.Add("Startup Date");                 
allviews.Add(viewName, viewFields, null, 100, true, true);

I am getting the following error:

Column 'Vacation Days Left' does not exist. It may have been deleted by another user.


web.Fields["Vacation Days Left"] => Not Null
employees.Fields["Vacation Days Left"] => Null  
employees.ContentTypes["Employee"].Fields["Vacation Days Left"] => Not Null

I can add the calculated field after deployment to the view manually.

2 Answers 2


I found the error. I was creating the calculated field like this:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">  
       DisplayName="Vacation Days Left"
       Group="Intranet Columns">
    <Formula>=[Vacation Days Earned]-[Vacation Days Taken]</Formula>

So I was missing the ResultType attribute. I should have added:


Are you updating your "employees" list after adding your columns by code? Because if you don't, the columns will be added to the site and function normally but will not be added to your list view!

  • I am creating the columns in an Elements.xml file. The calculated field is giving me errors, if I remove it the view will be created successfully.
    – user3470
    Jun 11, 2013 at 6:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.