Kentico CMS 10 - DocumentHelper 附件 URL

Kentico CMS 10 - DocumentHelper Attachment URL

当使用 CMS.DocumentEngine.DocumentHelper 检索自定义页面类型的文档时,如何获取附加到 Direct Uploader 表单控件 属性 类型的图像的路径?

如果 documents/page 正在通过以下方式检索:

DocumentQuery documents = DocumentHelper.GetDocuments("Custom.PageType")
   .Path("/some-path", PathTypeEnum.Children)
   .OnCurrentSite()
   .Culture("en-us")
   .Published()
   .Page(page, size);

然后遍历检索到的文档以投影到自定义 class:

foreach(var document in documents) {
    Foo foo = new Foo(document.getStringValue("SomeCustomColumnName", ""));
    foos.add(foo);
}

使用 getStringValue() 定位自定义页面类型 field/property 的直接上传器 returns 文档 GUID,例如 "123456f-5fa9-4f64-8f4b-75c52db096d5"

在转换中,我可以使用 GetFileUrl() 例如 GetFileUrl("AttachmentColumnName") 来获取路径,我如何在处理检索到的文档时在 ASPX 代码中使用它?

自定义页面类型数据通过 ASMX 服务和 Ajax 提供给客户端。返回的 JSON 数据用于 generate/append 页面标记,包括 <img />.

感谢您提供的任何帮助!

您可以在您的项目模板中尝试类似这样的内容:

/CMSPages/GetFile.aspx?guid=<%# Eval("SomeCustomColumnName")%>

如果您不想要损坏的图像,也可以在生成 link 之前检查 SomeCustomColumnName 是否为空。

另一个选项是将该文件上传转换为 URL 选择器,并允许用户将文件上传到媒体库。恕我直言,这可能是一种更好的方法。

我花了几个小时才弄明白。

就我而言,我能够使用以下方法获取图像 URL:

Guid pageGuid = ValidationHelper.GetGuid(this.GetValue("ProductPage"), new Guid());

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

CMS.DocumentEngine.TreeNode doc = DocumentHelper.GetDocuments()
    .Where(d => d.NodeGUID == pageGuid)
    .FirstOrDefault();

CMS.DocumentEngine.TreeNode pageNode = tree
    .SelectNodes()
    .WithGuid(doc.DocumentGUID)
    .OnCurrentSite()

var document = DocumentHelper.GetDocument(pageNode, tree);
Guid imageGuid = document.GetGuidValue("ImageProperty", new Guid());
DocumentHelper.GetAttachmentUrl(imageGuid, 0);