Tuesday, September 7, 2010

Getting a SharePoint Field Value In C# | ARB Security Solutions

Getting a SharePoint Field Value In C# | ARB Security Solutions


public static string GetFieldValue(SPListItem listItem, string fieldName)
{
string text = string.Empty;
if (fieldName == string.Empty)
{
return text;
}

try
{
object myObj = listItem[fieldName];
return ((myObj != null) ? myObj.ToString() : string.Empty);
}
catch
{
return string.Empty;
}
}

public static string GetHyperLinkFieldValue(SPListItem listItem, string fieldName)
{
string text = string.Empty;
if (fieldName == string.Empty)
{
return text;
}

try
{
SPFieldUrlValue value = new SPFieldUrlValue(listItem[fieldName].ToString());
return ((value != null) ? value.Url : string.Empty);
}
catch
{
return string.Empty;
}
}

0 comments: