How to retrieve an image from the KenticoCMS database
This article shows how to display an image if the web control property needs the format of a file ID like ImageUrl=”image.gif”.
Please note the GUID of the attached file is always stored in the column you have defined as the upload file. It means you could retrieve the file's GUID using the '
CMS.TreeEngine.TreeNode.GetValue(<fileColumnName>)' when replacing the '
<fileColumnName>' with the name of the field where the file was uploaded.
You could retrieve the URL of the file stored as the attachment of the particular document (TreeNode object) using the following piece of code:
Guid attachmentGuid = ValidationHelper.GetGuid(treeNode.GetValue(<fileColumnName>), Guid.Empty);
string nodeAlias = ValidationHelper.GetString(treeNode.GetValue("NodeAlias"), "");
string fileUrl = ResolveUrl(AttachmentManager.GetAttachmentUrl(attachmentGuid, nodeAlias));
See also: Applies to: Kentico CMS 3.x