PublishingPage Column Values
Adding a PublishingPage in SharePoint is covered here and in other places.
But I had the problem of trying to add content to columns that were not text-based. One was a link (RichLinkField) and the other was an image (RichImageField). My code did not throw an error when I assigned a text value:
But even though there was no exception thrown, the values were not set. It was as if those two lines were just ignored. I tried instantiating instances of RichImageField and RichLinkField, but the object model was way to confusing to try and understand just for this simple task. I did stumble on the ImageFieldValue and LinkFieldValue classes. The constructors of these will take an HTML string. I passed in valid HTML <img> and <a> tags, and it appears they were parsed and used to set the properties of the classes.
And it worked like a charm. For the link, http://www.address.com was set as the NavigateUrl property, and "Link Text" was set as the display value.
But I had the problem of trying to add content to columns that were not text-based. One was a link (RichLinkField) and the other was an image (RichImageField). My code did not throw an error when I assigned a text value:
page.ListItem["ImageColumnName"] = "http://www.address.com/images/image1.jpg";
page.ListItem["LinkColumnName"] = "http://www.address.com";
But even though there was no exception thrown, the values were not set. It was as if those two lines were just ignored. I tried instantiating instances of RichImageField and RichLinkField, but the object model was way to confusing to try and understand just for this simple task. I did stumble on the ImageFieldValue and LinkFieldValue classes. The constructors of these will take an HTML string. I passed in valid HTML <img> and <a> tags, and it appears they were parsed and used to set the properties of the classes.
page.ListItem["ImageColumnName"] = new ImageFieldValue("<img src='http://www.address.com/images/image1.jpg' />");
page.ListItem["LinkColumnName"] = new LinkFieldValue("<a href='http://www.address.com'>Link Text</a>");
And it worked like a charm. For the link, http://www.address.com was set as the NavigateUrl property, and "Link Text" was set as the display value.
Labels: sharepoint