访问页面子项中的附件-Kentico

访问页面子项中的附件-Kentico,kentico,kentico-mvc,Kentico,Kentico Mvc,我的结构如下: A国 |_问卷1 |_结果1 B国 |_问卷3 |_结果3 国家C |_问卷5 |_结果5 国家?属于CMS.文件夹pagetype,问卷和结果均属于CMS.文件pagetype,并包含一个附件(PDF)。 我正在尝试访问文件夹中每个出版物中附件的详细信息(名称、Guid、大小) 我试过以下方法 .Select(m => new { Country = m.DocumentName,

我的结构如下:

A国
|_问卷1
|_结果1
B国
|_问卷3
|_结果3
国家C
|_问卷5
|_结果5

国家?属于CMS.文件夹pagetype,问卷和结果均属于CMS.文件pagetype,并包含一个附件(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或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听起来更容易,但我无法做到这一点。

请看这篇解释附件工作的文章

您可以尝试以下选项:

  • 通过DocumentHelper.GetAttachment检索附件
  • Access document.Attachmets属性(每种页面类型都有此属性)

然后,您可以查看如下大小:attachment.AttachmentSize

页面的字段仅存储AttachmentGUID-so,您需要再次调用以使用GUID获取附件信息,或者以某种方式使用当前代码将GUID传递给DocumentHelper.GetAttachment方法,该方法将返回附件对象。@jurajo我已按建议进行了编辑,但为什么我不能多次访问子项。谢谢@dmitry bastron,我已经按照建议进行了编辑,但是为什么我不能在应用我的条件时多次访问孩子们呢。