Reputation: 38757
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)
.OnCurrentSite()
.Culture("en-us")
.Published()
.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", ""));
foos.add(foo);
}
Using getStringValue()
targeting the Direct Uploader field/property of the custom page type returns a document GUID such as "123456f-5fa9-4f64-8f4b-75c52db096d5"
.
In transformations, I can use GetFileUrl() such as GetFileUrl("AttachmentColumnName")
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!
Upvotes: 2
Views: 1011
Reputation: 1836
It took me a few hours to figure this out.
In my case, I was able to get the image URL using the following:
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);
Upvotes: 0
Reputation: 6117
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.
Upvotes: 2