Portal Engine Questions on portal engine and web parts.
Version 7.x > Portal Engine > Get attachment icon for CMS File View modes: 
User avatar
Member
Member
eric.savage-clyral - 1/2/2013 9:25:34 AM
   
Get attachment icon for CMS File
We add files via the CMS Desk tree, as a CMS File item. We list them in a repeater using a custom transformation on the CMS.File document type.

However, we want to display the icon using the macro GetAttachmentIconUrl. Now I'm having trouble getting the extension for the file? How can I access it? Eval("AttachmentExtension") returns blank.

User avatar
Member
Member
Accepted solutionAccepted solution
eric.savage-clyral - 1/4/2013 2:29:31 AM
   
RE:Get attachment icon for CMS File
I wrote a custom transformation:
public string GetFileExtension(object attachmentGuid)
{
AttachmentManager am = new AttachmentManager();
DataSet ds = am.GetAttachments(string.Format("AttachmentGUID = '{0}'", attachmentGuid.ToString()), "AttachmentOrder", false);

if (ds.Tables[0].Rows.Count > 0)
{
var attachment = am.GetAttachmentInfo(ds.Tables[0].Rows[0]["AttachmentGUID"].ToString(), CMSContext.Current.SiteName);
return attachment.AttachmentExtension;
}

return "";
}

And then used it like this:
<img src="<%# GetAttachmentIconUrl(GetFileExtension(Eval("FileAttachment")), "List") %>" />