How to display file size (attachment size) on a page using transformation

   —   
In this knowledge base article we will show how you can display the file size on the page using transformation.
You can e.g. call custom function in a transformation and use following code:

public static string GetAttachmentSize(object fileAttachmentGuidId)
{
// Get current attachment GUID
Guid attachGuid = CMS.GlobalHelper.ValidationHelper.GetGuid(fileAttachmentGuidId, Guid.Empty);
if (attachGuid != Guid.Empty)
{
// Get the attachment
AttachmentManager am = new AttachmentManager();
AttachmentInfo ai = am.GetAttachmentInfo(attachGuid, CMSContext.CurrentSite.SiteName);
if (ai != null)
{
string attExtension = ai.AttachmentExtension;
return DataHelper.FileSizeFormat(ai.AttachmentSize);
}
}
return string.Empty;
}


See also:

Applies to: Kentico CMS 4.0
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.