// 
// Returns the value of an Url-Field.
// 
public static string GetFieldValueUrl(this SPListItem item, string fieldName)
{
    if (item != null)
    {
        SPFieldUrlValue urlValue = new SPFieldUrlValue(item[fieldName] as string);
        return urlValue.Url;
    }
    else
    {
        return string.Empty;
    }
}
Example:
// Get the url of a SPFieldUrl field
string url = item.GetFieldValueUrl("URL");
// 
// Sets the value of an URL-Field.
// 
public static void SetFieldValueUrl(this SPListItem item, string fieldName, string url, string description)
{
    if (item != null)
    {
        item[fieldName] = new SPFieldUrlValue() 
                { 
                    Description = description, 
                    Url = url 
                };
    }
}
Example:
// Set the url and description of a SPFieldUrl field
item.SetFieldValueUrl("URL", "http://www.TestSite.com", "Test' Blog");
About Me
Labels
- General (1)
 - SharePoint 2007 (10)
 - SharePoint 2010 (3)
 
Buddies Blogs
Blog Archive
- 
▼ 
2010
                                (9)
                              
- 
▼ 
February
                                (9)
                              
- Opening PDF in separate window of Web Application...
 - SharePoint Groups vs. Active Directory Groups
 - If Current Navigation is not same as Parent Site N...
 - How to Retrieve Text from Enhanced Rich Text Colum...
 - Reading & Writing SPFieldUrl field values Programm...
 - Setting Multiple Values of SPFieldLookup Column Pr...
 - Setting Single Value of SPFieldLookup Column Progr...
 - Reading Multiple Values of SPFieldLookup Column Pr...
 - Reading Single Value of SPFieldLookup Column Progr...
 
 
 - 
▼ 
February
                                (9)
                              
 
Posted by
Sreedhar Chavali
Wednesday, 17 February 2010
Labels:
SharePoint 2007
Subscribe to:
Post Comments (Atom)