我在Kentico上创建了书店网站,我只使用他们的管理,并使用Kentico API显示我的网站上的数据,但是在获取与特定文档相关的附件文件时我感到非常困难,我使用
获取文档数据没有问题TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser);
var documents = tree.SelectNodes("CMS.Product");
还需要获取相关的附件文件,如书籍PDF ..我已尝试使用
实际上我正在搜索像GetAttachment()这样的东西。其中(“AttachmentFile”,“Ënglish文件”)
答案 0 :(得分:0)
使用类似
之类的东西解决了var Attachment = AttachmentInfoProvider.GetAttachments(226, true);
答案 1 :(得分:0)
您可以使用以下代码根据列中的值(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 :(得分:0)
这是来自Kentico的文档。此示例显示如何添加附件并修改其元数据。您可以忽略该部分。您必须使其通用以适用于所有示例。
// 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);
}