I have an event receiver that sets a value of a field using properties.AfterProperties
within ItemAdding
.
This works fine when adding a folder (with a custom content type) within the browser (the content type might not be set at that point but the value is in the field), but when adding a folder via code (list.RootFolder.SubFolders.Add("some folder name")
or via PowerShell, or even Client Object Model code), the event receiver fires but the value isn't being saved into the field.
Anyone else see this? I should mention it's within a Document Library.
SharePoint build number is: 14.0.7015.1000
Reproduction steps: Team Site with Shared Documents, custom column added called "TestColumn".
Event Receiver Code to reproduce:
/// <summary>
/// List Item Events
/// </summary>
public class TestReceiver : SPItemEventReceiver
{
/// <summary>
/// An item is being added.
/// </summary>
public override void ItemAdding(SPItemEventProperties properties)
{
base.ItemAdding(properties);
if (properties.List.Title == "Shared Documents")
{
properties.AfterProperties["TestColumn"] = "Foo";
}
}
}
PowerShell to reproduce:
$w = get-spweb http://sitecoll/
$w.Lists["Shared Documents"].RootFolder.SubFolders.Add("TestFolder").Update()