API Questions on Kentico API.
Version 6.x > API > Document Attachments through API View modes: 
User avatar
Member
Member
cwyatt-emh - 4/17/2012 1:01:08 PM
   
Document Attachments through API
I have a document type and I created a grouped attachment field (Document attachments). How can I get the group GUID from the field name through the API? I have tried the following but I get only the guid.empty value back.

 Guid attGuid = CMS.GlobalHelper.ValidationHelper.GetGuid(CMSContext.CurrentDocument.GetValue(sColumnName), Guid.Empty);

User avatar
Member
Member
kentico_michal - 4/18/2012 3:32:41 AM
   
RE:Document Attachments through API
Hi,

First of all, the Document attachment field is empty. It does not contain the AttachmentGroupGUID as you might expect. Group attachments are stored in CMS_Attachment table. The only difference between standard attachment and group attachment is that AttachmentGroupGUID column is filled with GUID in case the attachment is group attachments.

Below you can find code example which you need to use to get AttachmentGroupGUID of your attachment field (The code example is for cms.news document type and field NewsAttachments which is of type “Document attachments”):
using CMS.SettingsProvider;
using CMS.FormEngine;
DataClassInfo dci = DataClassInfoProvider.GetDataClass("cms.news");

if (dci != null)
{
FormInfo fi = new FormInfo(dci.ClassFormDefinition);
FormFieldInfo ffi = fi.GetFormField("NewsAttachments");
Guid AttachmentGroupGUID = ffi.Guid;
}


Best regards,
Michal Legen