使用 Kentico 获取文档附件 API

Getting document attachments using Kentico API

我在 Kentico 上创建了书店网站,我只使用了他们的管理,并使用 Kentico API 显示我网站上的数据,但是我很难获取与特定文档相关的附件文件,我有文档数据使用

没问题
TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser);
var documents = tree.SelectNodes("CMS.Product");

还需要获取相关的附件文件,例如书籍 PDF。我尝试使用

  1. 文档附件
  2. 附件信息
  3. 附件信息提供者 类 但我无法获取数据.. 如果有人帮助我,我将不胜感激。

实际上我正在搜索类似 GetAttachment().Where("AttachmentFile","Èenglish File")

使用类似

后解决
var Attachment = AttachmentInfoProvider.GetAttachments(226, true);

您可以使用如下代码根据列 (CMS_Attachment table) 中的值过滤返回的附件:

   var attachment = AttachmentInfoProvider.GetAttachments()
       .WhereEquals("AttachmentName", "Englishfile")
       .And()
       .WhereEquals("AttachmentExtension", "jpg")
       .TopN(1)
       .FirstOrDefault();

   if (attachment != null)
   {
         // attachment was found
   }

此代码将获得一个 .jpg 文件,其中附件名称等于 "EnglishFile"

这来自 Kentico 文档。此示例说明如何添加附件并修改其元数据。您可以忽略 part.You 必须使其通用以适用于所有示例。

Kentico 9 API Links

// Creates a new instance of the Tree provider
TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser);

// Gets a page
TreeNode page = tree.SelectSingleNode(SiteContext.CurrentSiteName, "/Articles", "en-us");

if (page != null)
{
    // Gets an attachment by file name
    AttachmentInfo attachment = DocumentHelper.GetAttachment(page, "file.png", tree);

    // Edits the attachment's metadata (name, title and description)
    attachment.AttachmentName += " - modified";
    attachment.AttachmentTitle = "Attachment title";
    attachment.AttachmentDescription = "Attachment description.";

    // Ensures that the attachment can be updated without supplying its binary data
    attachment.AllowPartialUpdate = true;

    // Saves the modified attachment into the database
    AttachmentInfoProvider.SetAttachmentInfo(attachment);
}