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

Was it helpful?

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++;
        }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top