2

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.

0

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.

| improve this answer | |

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.