I have the following structure:
Country A
|_Questionnaire 1
|_Result 1
Country B
|_Questionnaire 3
|_Result 3
Country C
|_Questionnaire 5
|_Result 5
Country ? are of CMS.folder pagetype and both questionnaire and result are of the CMS.file pagetype and contain one attachment (PDF). I am trying to access the details of the attachment (name, Guid, size) in each publication available in a folder.
I have tried the following
.Select(m => new
{
Country = m.DocumentName,
questionnaire = m.Children.WithAllData.Where(w => w.DocumentName.Contains("Questionnaire")).Select(s => s.GetValue("PDF")),
result = m.Children.WithAllData.Where(w => w.DocumentName.Contains("Result")).Select(s => s.GetValue("PDF"))
})
.ToList();
I can obrain the GUID of the attachment available in the Questionnaire file for each folder but I can not get the value of result as it seems the repetition of WithAllData twice prevents this.
How could I also access the size and name of the attachment? I tried including AttachmentSize or AttachmentName
but i had no success with children of the current node.
What would be the best approach to do what I am trying to do?
---------------- Update ------------------------------
As suggested, this is what I tried:
.Select(m => new
{
Country = m.DocumentName,
questionnaire = GetDocs(m.Children.Where(w => w.DocumentName.Contains("Questionnaire")).FirstOrDefault()),
result = GetDocs(m.Children.Where(w => w.DocumentName.Contains("Result")).FirstOrDefault())
})
.ToList();
private PublicationSimpleDto GetDocs(TreeNode tree)
{
PublicationSimpleDto publication = null;
if (tree != null)
{
foreach (DocumentAttachment attachment in tree.Attachments)
{
publication = new PublicationSimpleDto()
{
Title = attachment.AttachmentTitle,
Extension = attachment.AttachmentExtension.Replace(".", "").ToUpper(),
AttachmentUrl = attachment.AttachmentGUID.ToString(),
Size = attachment.AttachmentSize
};
}
}
return publication;
}
However, it doesn't catch the result one it seems that I can not repeat .children
several times. It was the same issue with:
questionnaire = m.Children.WithAllData.Where(w => w.DocumentName.Contains("Questionnaire")).Select(s => s.GetValue("PDF")),
result = m.Children.WithAllData.Where(w => w.DocumentName.Contains("Result")).Select(s => s.GetValue("PDF"))
Using directly the Attachment GUID instead of the TreeNode of the page sounded easier but I am unable to do so.