Recently I was attempting to deploy a ListTemplate and related ListInstance. It occurred to me that I should also attempt to load the initial data that will be in my ListInstance. In the declaration of a ListInstance, you are supposed to be able to populate data according to MSDN's documentation. I found this to be true in simple cases. If however you want to set a more complicated value than a string or an integer (like a person), I could not find a format by which this would work.
So I came up with this workaround.
In a feature, create a class that extends SPFeatureReceiver that overrides the FeatureActivated method. In this method, retrieve a reference to the web and then the list you wish to insert data for. Once you have the SPList, the Items property has an Add method that returns an SPListItem object. This object has a collection of fields that can be set.
To get a reference to a person in the system, use the web.AllUsers property.
After you set the necessary fields, call the Update method.
Note: The ItemAdded event is fired when you call the Add method so don't expect to use any of the values that you set after you call Items.Add().
Here is the code that I used to make this work:
1:
2: public class HMBEmployeeListFeatureReceiver : SPFeatureReceiver
3: {
4: public override void FeatureActivated(SPFeatureReceiverProperties properties)
5: {
6: SPWeb web = properties.Feature.Parent as SPWeb;
7: if (web == null)
8: {
9: SPSite site = properties.Feature.Parent as SPSite;
10: web = site.RootWeb;
11: }
12: if (web != null)
13: {
14: using (web)
15: {
16: SPList employeeList = web.Lists["HMB Employees"];
17: SPListItem item = employeeList.Items.Add();
18: item["FirstName"] = "Frederick";
19: item["Nickname"] = "Rick";
20: item["Last_x0020_Name"] = "Kierner";
21: item["Associated_x0020_User"] = web.AllUsers["hmbnet\\rk"];
22: item.Update();
23: }
24: }
25: }