FileNames property is always null

May 23, 2013 at 8:26 AM
Hi,

I am trying to get the images associated with a content item but I always get null for the FileNames property.

I am trying to get the images of a content item on a controller and my code is the following:
public static IList<string> GetItemImages(ContentItem item, string fieldName)
        {
            IList<string> images = new List<string>();
            IEnumerable<ContentField> fields = item.Parts.Select<ContentPart, ContentField>(x => 
                                                        x.Fields.FirstOrDefault(f => String.Equals(f.Name, fieldName)))
                                                    .Where(x => (x != null));

            if (fields != null)
            {
                ContentField field = fields.FirstOrDefault<ContentField>(x => String.Equals(x.Name, fieldName));

                if (field is AgileUploaderField.Fields.AgileUploaderField)
                {
                    AgileUploaderField.Fields.AgileUploaderField agileUploadField = field as AgileUploaderField.Fields.AgileUploaderField;
                    if ((agileUploadField != null) && (!string.IsNullOrEmpty(agileUploadField.FileNames)))
                    {
                        foreach (string filename in agileUploadField.FileNames.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
                        {
                            images.Add(filename);
                        }
                    }
                }
            }

            return images;
        }
However in the administration I can see the image when I view the content item.

Any idea why the property is null?