How to get data of document attachment using API

   —   
This article describes how you can get data of attachment (e.g. file extension) from particular field of current document.
To achieve this functionality please use the sample code bellow:

using CMS.FileManager;
...
Guid attGuid = CMS.GlobalHelper.ValidationHelper.GetGuid( CMSContext.CurrentDocument.GetValue("NameOfFieldWithAttachment"), Guid.Empty);
if (attGuid != Guid.Empty)
{
AttachmentManager am = new AttachmentManager();
AttachmentInfo ai = am.GetAttachmentInfo(attGuid, CMSContext.CurrentSite.SiteName);
string attExtension = ai.AttachmentExtension;
}


See also: devnet.kentico.com/Knowledge-Base/API-and-Internals/How-to-retrieve-an-image-from-the-KenticoCMS-datab.aspx
devnet.kentico.com/Knowledge-Base/API-and-Internals/How-to-display-link-to-a-file-or-document-without-.aspx

Applies to: Kentico CMS 3.1a
Share this article on   LinkedIn

Juraj Ondrus

Hi, I am the Technical support leader at Kentico. I'm here to help you use Kentico and get as much as possible out of it.