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("Employee");
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.
Notes:
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.