【发布时间】:2020-01-10 02:45:43
【问题描述】:
我有以下结构:
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 听起来更容易,但我无法这样做。
【问题讨论】:
-
该页面的字段仅存储 Attachmend GUID - 因此,您需要再次调用以使用 GUID 获取附件信息,或者以某种方式使用您当前的代码将 GUID 传递给 DocumentHelper.GetAttachment方法将返回附件对象。
-
@jurajo 我已按照建议进行了编辑,但为什么我不能多次访问孩子。
标签: kentico kentico-mvc