IEnumerable<DocumentAttachment> is empty in my controller

Ben Murphy asked on August 22, 2019 13:00

I am using the standard method to get the properties of my page:

ClientLogosDatasource datasourceItem = ClientLogosDatasourceProvider.GetClientLogosDatasource(datasourceNodeGuid, "en-us", SiteContext.CurrentSiteName).Columns("ClientLogosDatasourceHeadingText", "ClientLogosDatasourceImages");

Which has an 'Attachments' form component 1

But when I attempt to enumerate over the property in my MVC application, the enumeration is empty. 2

Stepping through the code, it basically skips the foreach completely. I'm not sure why the Images property is null/empty.

Any help would be appreciated!

Recent Answers


Brenden Kehren answered on August 22, 2019 15:27

Here's the basic API example (not MVC specific) but should get you in the right direction.

// Creates a new instance of the Tree provider
TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser);

// Gets a page
TreeNode page = tree.SelectNodes()
    .Path("/Articles")
    .OnCurrentSite()
    .Culture("en-us")
    .TopN(1)
    .FirstOrDefault();

if (page != null)
{
    // Iterates over all attachments of the page
    foreach (DocumentAttachment attachment in page.AllAttachments)
    {
        // Perform any action with the attachment object (DocumentAttachment)
    }
}

// To get only unsorted attachments, use the TreeNode.Attachments collection
// To get only page field attachments, use the TreeNode.GroupedAttachments collection
2 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.