我有以下结构:
国家 A
|_问卷 1
|_结果 1
国家 B
|_问卷 3
|_结果 3
国家 C
|_问卷 5
|_结果 5
国家 ?属于CMS.folder 页面类型,问卷和结果都属于CMS.file 页面类型并包含一个附件 (PDF)。我正在尝试访问文件夹中每个可用出版物中附件的详细信息(名称、Guid、大小)。
我试过以下
.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();
我可以在每个文件夹的调查问卷文件中获取附件的 GUID,但我无法获得结果的值,因为似乎重复 WithAllData 两次阻止了这种情况。我怎样才能访问附件的大小和名称?我尝试包括AttachmentSize or AttachmentName
但我没有成功处理当前节点的子节点。
做我想做的事情的最佳方法是什么?
- - - - - - - - 更新 - - - - - - - - - - - - - - -
正如所建议的,这是我尝试过的:
.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;
}
但是,它没有抓住结果,似乎我不能重复.children
几次。这是同样的问题:
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"))
直接使用附件 GUID 而不是页面的 TreeNode 听起来更容易,但我无法这样做。