views:

36

answers:

0

Site > Site Settings > Site Columns

site column page (mngfield.aspx) displays unknown error

I get an unknown error. This happens when I add custom columns from a console app using SPField. The columns are added with the given properties (verified by SharePoint manager).

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;

namespace AddSiteColumns
{
class Program
{
static void Main(string[] args)
{
using (SPSite siteCollection = new SPSite("https://server/sites/workforce"))
using (SPWeb webSite = siteCollection.RootWeb)
{
try
{
Console.WriteLine("Creating New Site Columns....... ");
string[,] siteColumns = new string[,] { { "TEST_Column_1", SPFieldType.Text.ToString() }, {"Column_Mod_Date", "DateTime"}, {"Col_Mod_By", "Text"}};
//Get both bounds
int bound0 = siteColumns.GetUpperBound(0);
int bound1 = siteColumns.GetUpperBound(1);
for (int i=0; i<=bound0;i++)
{
string s1 = siteColumns[i, 0];
string s2 = siteColumns[i, 1];
SPField spf = null;
spf = webSite.Fields.CreateNewField(s2, s1);
webSite.Fields.Add(spf);
spf = webSite.Fields[s1];
spf.StaticName = s1;
spf.ShowInDisplayForm = true;
spf.ShowInListSettings = true;
spf.ShowInEditForm = false;
spf.ShowInNewForm = false;
spf.ShowInVersionHistory = true;
spf.ShowInViewForms = true;
spf.AllowDeletion = false;
spf.Required = false;
spf.Group = "Workforce Custom Columns";
spf.Update();
webSite.Update();
Console.WriteLine("Done...... ");
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
return;
}
}
}
}