using (SPSite site = new SPSite(workflowProperties.SiteUrl))
{
using (SPWeb web = site.OpenWeb())
{
SPList spList = web.Lists["MySpList"];
SPQuery spQuery = new SPQuery();
spQuery.Query = "<Where>--</And></Where>";
SPListItemCollection collListItems = spList.GetItems(spQuery);
foreach (SPListItem listItem in collListItems)
{
string EmpName = GetSPUser(listItem, "UserName");
}
}
}
public SPUser GetSPUser(SPListItem spListItem, String fieldName)
{
SPUser spUser = null;
try
{
if (fieldName != string.Empty)
{
SPFieldUser field = spListItem.Fields[fieldName] as SPFieldUser;
if (field != null && spListItem[fieldName] != null)
{
SPFieldUserValue fieldValue = field.GetFieldValue(spListItem[fieldName].ToString()) as SPFieldUserValue;
if (fieldValue != null)
{
spUser = fieldValue.User;
}
}
}
}
catch (Exception ex)
{
throw ex;
}
return spUser;
}
No comments:
Post a Comment