我具有以下结构:
国家A| _问卷1| _结果1国家B| _问卷3| _结果3C国| _问卷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听起来更容易,但我无法这样做。
我具有以下结构:国家A | _Questionnaire 1 | _Result 1国家B | _Questionnaire 3 | _Result 3国家C | _Questionnaire 5 | _Result 5国家?属于CMS.folder页面类型,并且...
[请查看此Kentico docs article,解释带有附件的工作。