my aim is to use a Sharepoint 2013 Foundation this way:
define a template Document Library, ProjectTemplate
define a list of projects, with a "category" column
an itemAdded event receiver on the projects list creates a Doc Lib based on the ProjectTemplate each time a new project gets added; the Doc Lib is named with the project name
for the category column of the Document Library, sets a default value equal to the added project' category. Everything is working, but the default value part. This is the code:
public override void ItemAdded(SPItemEventProperties properties) { SPWeb myWeb = properties.Web; string projectName = properties.ListItem["Project Name"].ToString(); var customTemplate = myWeb.ListTemplates["ProjectTemplate"]; Guid myItemGuid = myWeb.Lists.Add(projectName , projectName , customTemplate); SPList myItem = myWeb.Lists[myItemGuid]; myItem.Fields["Project Category"].DefaultValue = "Test default value"; myItem.Update(); properties.ListItem.Update(); base.ItemAdded(properties); }
I thought there was something dealing with maybe asynchronous execution of myWeb.Lists.Add, so I tried setting the defaultvalue for another existing Document Library - without luck anyway.
I even tried browsing with Sharepoint Manager, to see if the defaultvalue gets filled, or filling it by hand. No results.
Is field.defaultvalue managed in Sharepoint Foundation? It is not available from the site settings administration interface
Are custom fields accessible within ItemAdded event?