I'm programmatically creating Site Collections. The only thing I'd like to add to the newly created Site Collection are some Custom Columns that I've added manually in other examples..
The code I'm using is this:
string SiteCollectionUrl = "/sites/Prova212222";
Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(() =>
{
var Application = SPWebApplication.Lookup(new Uri("http://sp2010dev:44411/"));
Application.Sites.Add(SiteCollectionUrl, "virtualsp\\Administrator", string.Empty, 1033, "STS#0", "virtualsp\\Administrator", "virtualsp\\Administrator", String.Empty);
using (SPSite site = new SPSite("http://sp2010dev:44411" + SiteCollectionUrl))
{
using (SPWeb web = site.OpenWeb())
{
site.AllowUnsafeUpdates = true;
web.AllowUnsafeUpdates = true;
web.AvailableFields.Add("tt_content_id_padre", SPFieldType.Text, true);
//And so on for other columns
}
}
});
When I reach the Add method system raises this exception:
This functionality is unavailable for field collections not associated with a list.
How can I solve this problem? I'm not interested in creating content type and so on, the only thing i need is the columns as I added manually!
Thank you