I need to create a site column programmatically during feature activation (requirements - supose I can't change that).
My code is fairly straight forward:
string internalName = web.Fields.AddLookup("foo", someList.ID, false); // *field name*, *ID of the list to point* and *required*, respectively. SPFieldLookup foo = (SPFieldLookup)web.Fields.GetField("foo"); foo.Group = "bar"; foo.update(); web.update();
The field is created, alright - but when I navigate to the site where it was created, it does not show up in the "site columns" page, in the site administration.
I can't add it again because it's already in the site. I can't associate it to any content type because it doesn't show up in any page at all. I can't delete it programatically, either:
- With C# it tells me there is some list or content type using the field (which is not true at all)
- and with Powershell I either get no errors, or get a "wrong parameters" error when running
Deletein any form below. But even after the commands run without errors the column is not truly deleted (I can still fetch it via C# and Powershell):
$site = Get-SPSite(siteUrl) $web = $site.rootweb $web.Fields["foo"].delete() $foo = $web.Fields["foo"] $foo.delete() $web.Fields.Delete($foo) etc...
(The only web in the site colletion is the root one.)
I have tried the brute force solution, that is, deleting the site collection and recreating it again (I'm just fiddling with a dev environment for now), thinking my site might have gone corrupt. It just doesn't solve the problem. When I create it again in a whole new site, the column stays there, and I can neither use it nor delete it.