【问题标题】:Getting document attachments using Kentico API使用 Kentico API 获取文档附件
【发布时间】:2016-04-25 22:55:20
【问题描述】:

我在 Kentico 上创建了书店网站,我只使用了他们的管理并使用 Kentico API 显示来自我网站的数据,但在获取与特定文档相关的附件文件时遇到了困难,我使用文档数据没有问题

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

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

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

实际上是在搜索 GetAttachment().Where("AttachmentFile","Ënglish File") 之类的东西

【问题讨论】:

    标签: kentico


    【解决方案1】:

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

       var attachment = AttachmentInfoProvider.GetAttachments()
           .WhereEquals("AttachmentName", "Englishfile")
           .And()
           .WhereEquals("AttachmentExtension", "jpg")
           .TopN(1)
           .FirstOrDefault();
    
       if (attachment != null)
       {
             // attachment was found
       }
    

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

    【讨论】:

      【解决方案2】:

      使用类似的东西后解决

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

      【讨论】:

        【解决方案3】:

        这是来自 Kentico 文档。此示例显示如何添加附件并修改其元数据。您可以忽略该部分。您必须使其通用以适用于所有示例。

        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);
        }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-04-15
          • 2014-10-19
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多