Question

I have custom module for employee and i want to display cv document side on listing of employee in grid view.

how to get size of document? i have used media library to upload cv. can someone help me on it

thanks

Était-ce utile?

La solution

Please follow the below code for get the file size. Add Property in your ABCPart.cs( public string FileSize { get; set; })

After get list of record then add below code for get file size.

 int cnt = 0;
        foreach (var item in lstDocument)
        {
            var b = item.Fields.Single(f => f.Name == "YourMediaLibararyPickerFieldName");
            if (item.Fields.Single(f => f.Name == "YourMediaLibararyPickerFieldName") != null)
            {
                var field = _contentManager.Get(((Orchard.MediaLibrary.Fields.MediaLibraryPickerField)item.Fields.Single(f => f.Name == "YourMediaLibararyPickerFieldName")).Ids[0]);
                if (field != null && field.ContentType == "Document")
                {
                    long a = ((Orchard.MediaLibrary.Models.DocumentPart)_contentManager.Get(((Orchard.MediaLibrary.Fields.MediaLibraryPickerField)item.Fields.Single(f => f.Name == "YourMediaLibararyPickerFieldName")).Ids[0]).As<Orchard.MediaLibrary.Models.DocumentPart>()).Length;
                    lstDocument[cnt].FileSize = (a / 1024).ToString() + " KB";
                }
                else
                {
                    lstDocument[cnt].FileSize = "-";
                }
            }
            else
            {
                lstDocument[cnt].FileSize = "-";
            }
            cnt++;
        }
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top