Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am using the Object Model and the Microsoft.SharePoint.Publishing.Fields.LinkFieldValue namespace in an attempt to set the value of a Hyperlink Column on a SharePoint 2007 Publishing Site.

However, if the field has no value prior to my update, I get System.ArgumentNullException when I attempt the assignment.

using Pub = Microsoft.SharePoint.Publishing;

int id = 1;
SPListItem item = SPContext.Current.List.GetItemById(itemId);
if(item.Fields.ContainsField("MyHyperlink"))
{
    Pub.Fields.LinkFieldValue destination = 
        new Pub.Fields.LinkFieldValue("<a href=\"www.google.com\">Link</a>");
    item["MyHyperlink"] = destination; //Null Exception here for item["MyHyperlink"]
    item.SystemUpdate(true);
}
share|improve this question

1 Answer 1

up vote 0 down vote accepted

Sorry to post a link, but did you check out this example: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.publishing.fields.linkfieldvalue(v=office.12).aspx

share|improve this answer
    
Thanks. - My error was more along the lines that I was using a different column type than I had thought. Your link worked once I created a site column using the type "Hyperlink with formatting and constraints for publishing" the code above worked. I was getting the null error because the site column was actually the "Hyperlink or Picture" column it just expected a string with the URL and Display Text comma delimited –  W4keDotNet Oct 24 '11 at 13:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.