Alexander Staroselsky Alexander Staroselsky - 1 year ago 57
ASP.NET (C#) Question

Kentico CMS 10 - DocumentHelper Attachment URL

When using the CMS.DocumentEngine.DocumentHelper to retrieve documents of a custom page type, how would one get the path of an image attached to a Direct Uploader form control property type?

If documents/page are being retrieved in the following way:

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

Then looping through retrieved documents to project to a custom class:

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

targeting the Direct Uploader field/property of the custom page type returns a document GUID such as

In transformations, I can use GetFileUrl() such as
to get the path, how could I use that in ASPX code behind when working with retrieved documents?

The custom page type data is provided to the client via an ASMX service and Ajax. The returned JSON data is used to generate/append markup to the page, including an
<img />

Thank you for any help you can provide!

Answer Source

You can try something like this in your item template:

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

You can also check to see if SomeCustomColumnName is empty or not before generating that link too if you don't want a broken image.

The other option is to convert that file upload to a URL selector and allow the users to upload files to the media library. This is probably a better approach IMHO.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download