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 trying to insert summary links into a custom content type.

PublishingPage newPage = publishingWeb.GetPublishingPages().Add(filename, layout);
                newPage.Title = page.NewPage.Title;
                newPage.Update();

            // Update the fields on the new page
            SPFile file = currentWeb.GetFile(newPage.Url);
            SPListItem newPageItem = file.Item;
            newPageItem["Contact Info"] = page.NewPage.ContactInfo;                
            newPageItem["Summary Links"] = resolveSummaryLinks(page.NewPage.SummaryLinks); 
            newPageItem.Update();

my "resolveSummaryLinks" code just creates a "SummaryLinkCollection" and returns that. However; the new page doesn't have any value for the "Summary Links" field. How should I be populating this field?

Thanks for any help.

share|improve this question
add comment

1 Answer 1

I did manage to figure it out. My collection needs to be serialized to a string THEN the xml declaration that is created needs to be removed.

SummaryLinkCollection collection = new SummaryLinkCollection();
//Other code to populate the collection
MemoryStream stream = new MemoryStream();
XmlWriter writer = XmlWriter.Create(stream);
collection.Serialize(writer);
string x = string.Empty;
writer.Flush();
x = Encoding.UTF8.GetString(stream.ToArray());
string y= x.Replace("<?xml version=\"1.0\" encoding=\"utf-8\"?>", "");
return y;

The removal of the xml declaration was very important, if not done, then trying to add the value would raise an exception that the xml declaration was unexpected.

share|improve this answer
add comment

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.