0

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);
}
0

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

  • 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

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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