ASPX templates
Version 4.x > ASPX templates > Using image selection fields - how do I get a file's URL given its GUID? View modes: 
User avatar
Certified Developer 9
Certified Developer 9
jkh80 - 7/8/2009 1:09:26 PM
   
Using image selection fields - how do I get a file's URL given its GUID?
I have set up a document type that has a number of image selection fields. I am trying render the document in a template I have set up for this document type, but I am having trouble getting the image URL.

In the template I am working, I am using a DataRow object that represents the document, getting it like this:

DataRow row = CMSContext.CurrentDocument.DataRow;

I can access the image selection fileds I have set up this way, but they are only the GUIDs.

There is information in the documentation about how to get the URL in a transformation, but calling the same CMS.Controls.CMSAbstractTransformation.GetDocumentUrl(Object, Object) method in my template code-behind does not work.

I have also tried using the methods in the CMS.FileManager.AttachmentManager, also to no avail.

So, given a GUID, how do I retrieve information about the document? I just need the URL for the image document that the GUID represents, but if I can lode the TreeNode object from the GUID, that's fine as well.

Any ideas?



User avatar
Member
Member
bluerhino_avanmeter - 7/8/2009 1:39:41 PM
   
RE:Using image selection fields - how do I get a file's URL given its GUID?
Check out http://devnet.kentico.com/docs/4_0/controls/basicdatalist.htm, especially the code example.


<itemtemplate>
<div style="width: 100%">
<h3>
<%# Eval("ProductName") %>
</h3>
<img alt="<%# Eval("ProductName") %>_img" src='<%# ResolveUrl("~/CMSPages/GetFile.aspx?guid=" + Eval("ProductPhoto").ToString()) %>' />
</div>
</itemtemplate>

I think that GetFile.aspx will get you what you want.

Documentation of the GetFile.aspx page:
http://devnet.kentico.com/docs/4_0/devguide/getfile_aspx_parameters.htm

User avatar
Certified Developer 9
Certified Developer 9
jkh80 - 7/8/2009 3:34:36 PM
   
RE:Using image selection fields - how do I get a file's URL given its GUID?
Thank you, bluerhino_avanmeter, that did the trick!

Though, I am still curious as to whether or not there is a way to get a TreeNode object from the API using the node's GUID.

User avatar
Member
Member
bluerhino_avanmeter - 7/8/2009 4:03:35 PM
   
RE:Using image selection fields - how do I get a file's URL given its GUID?
You can use the CMS.TreeEngine.TreeProvider class, it provides methods for selecting one or multiple nodes.

The function SelectSingleNode accepts a node GUID for one of its overloads.

User avatar
Certified Developer 9
Certified Developer 9
jkh80 - 7/9/2009 5:40:33 PM
   
RE:Using image selection fields - how do I get a file's URL given its GUID?
Not sure how I missed that, thanks!

User avatar
Kentico Developer
Kentico Developer
kentico_martind - 7/11/2009 1:32:44 PM
   
RE:Using image selection fields - how do I get a file's URL given its GUID?
Hello,

Just FYI, you can find some examples for selecting nodes in 'Select Nodes' section in Developers Guide. You can also find more details about each method in Kentico CMS API reference.

Best Regards,

Martin Dobsicek

User avatar
Member
Member
robert-tailor.co - 8/2/2012 11:27:49 PM
   
RE:Using image selection fields - how do I get a file's URL given its GUID?
This answers my question exactly!

Or at least it would if the links in your response worked...

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 8/3/2012 1:44:10 AM
   
RE:Using image selection fields - how do I get a file's URL given its GUID?
Hi,

I am sorry for the broken link - I have already updated it.

Best regards,
Juraj Ondrus

User avatar
Member
Member
annaharris170-gmail - 5/4/2013 7:50:52 AM
   
RE:Using image selection fields - how do I get a file's URL given its GUID?
The code looks fine, just check the path of the folder where all the images are stored.