SPListItem properties metadata columns with C# Part2

Part 1

To change Propertie fields that are not plain text fields there are some problems in addign specific data to these columns.

for example:
You want to add a user to the assigned to field from an item in a TaskList

This won't work!
oNewTask[“Assigned To”] = “DOMAIN\\Tom.VanGaever”;

Instead you should use

when you are in a WorkFlow you can use
m_selectItem = WorkflowProperties.Item;
newTask[“Assigned To”] = m_selectedItem.Web.AllUsers[“DOMAIN\\Tom.VanGaever”];

Otherwise use the SPWeb object of your sharepointsite
SPWeb oWebsite = collWebsites[“Site_Name”];
newTask[“Assigned To”] = oWebsite.AllUsers[“DOMAIN\\Tom.VanGaever”];

A User field contains a string in the form ID;#User_Display_Name, where ID is the member ID of the associated user. The following example parses the value of an Assigned To field to return an SPUser object.

string strUserValue = oList["Assigned To"];
int intIndex = strUserValue.IndexOf(';');
int intID = Int32.Parse(strUserValue.Substring(0, intIndex));
SPUser oUser = oWebsite.SiteUsers.GetByID(intID);

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)