在果园的自定义模块中显示媒体库文件大小



>我有员工的自定义模块,我想在网格视图中的员工列表中显示简历文档端。

如何获取文档的大小? 我使用媒体库上传简历。 有人可以帮助我

谢谢

请按照以下代码获取文件大小。在 ABCPart.cs( public string FileSize { get; set; } 中添加属性 )

获取记录列表后,添加以下代码以获取文件大小。

 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++;
        }

最新更新