If you would like to discuss anything, please contact me via email: Howard.Bayliss@sequence.co.uk

Friday, May 27, 2011

SharePoint PublishingPageImage src

For an article page, SharePoint stores the value of the Publishing Image field in a particular format. Here is an example:

<img alt="" src="/SiteCollectionImages/home.jpg" style="BORDER: 1px solid; ">

I wanted to extract the value of the "src" attribute. Here is the code I used:

string fullValue = String.Format("{0}", file.Item[FieldNames.PUBLISHING_PAGE_IMAGE]);

string src = String.Empty;

if (String.IsNullOrEmpty(fullValue) == false)
string xml= String.Format("{0}</img>", fullValue);
string src = XElement.Parse(xml).Attribute("src").Value;

No comments:

Post a Comment