0

我有以下结构:

国家 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 听起来更容易,但我无法这样做。

4

1 回答 1

0

请查看这篇解释附件工作的Kentico 文档文章。

您可以尝试以下选项:

  • 通过 DocumentHelper.GetAttachment 检索附件
  • 访问 document.Attachmets 属性(每个页面类型都有这个属性)

然后您将能够查看例如这样的大小:attachment.AttachmentSize

于 2020-01-09T11:25:35.160 回答