我具有以下结构:
A国
| _问卷1
| _结果1
国家B
| _问卷3
| _结果3
C国
| _问卷5
| _结果5
国家?属于 CMS.folder 页面类型,调查表和结果均属于 CMS.file 页面类型,并且包含一个附件(PDF)。 我正在尝试访问文件夹中每个出版物中附件的详细信息(名称,向导,大小)。
我尝试了以下
.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听起来更容易,但我无法做到这一点。