<dx:BootstrapFileManager runat="server" ID="FileManagerCustomColumns" OnDetailsViewCustomColumnHeaderFilterFillItems="FileManagerCustomColumns_DetailsViewCustomColumnHeaderFilterFillItems"
CustomFileSystemProviderTypeName="MetadataFileSystemProvider" Height="480px">
<SettingsToolbar ShowPath="false" />
<SettingsAdaptivity Enabled="true" CollapseFolderContainerAtWindowInnerWidth="991" />
<Settings RootFolder="~/Content/FileManager/Files" ThumbnailFolder="~/Content/FileManager/Thumbnails" />
<SettingsFileList View="Details" ShowFolders="true">
<DetailsViewSettings>
<Columns>
<dx:BootstrapFileManagerDetailsColumn FileInfoType="Thumbnail" AdaptivePriority="2" />
<dx:BootstrapFileManagerDetailsColumn FileInfoType="FileName" AdaptivePriority="1" />
<dx:BootstrapFileManagerDetailsColumn FileInfoType="LastWriteTime" AdaptivePriority="2" />
<dx:BootstrapFileManagerDetailsCustomColumn Caption="Type" Name="Type" ItemMetadataKey="Type"
ShowHeaderFilterButton="True" AllowSort="True" AllowTextTruncationInAdaptiveMode="true" />
<dx:BootstrapFileManagerDetailsColumn FileInfoType="Size" AdaptivePriority="2" />
</Columns>
</DetailsViewSettings>
</SettingsFileList>
</dx:BootstrapFileManager>
protected void FileManagerCustomColumns_DetailsViewCustomColumnHeaderFilterFillItems(object source, DevExpress.Web.Bootstrap.BootstrapFileManagerDetailsViewCustomColumnHeaderFilterFillItemsEventArgs e) {
if(e.Column.Name.Equals("Type")) {
e.Values.Clear();
e.AddShowAll();
e.AddValue("Folders", string.Empty, "Type In ('Folder','Compressed (zipped) Folder (.zip)')");
e.AddValue("Documents", string.Empty, "Type In ('Text Document (.txt)','Rich Text Format (.rtf)','XML Document (.xml)')");
e.AddValue("Images", string.Empty, "Type In ('JPG File (.jpg)','PNG File (.png)')");
e.AddValue("Media Files", string.Empty, "Type In ('AVI File (.avi)','MP3 File (.mp3)')");
}
}
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using DevExpress.Web;
public class MetadataFileSystemProvider : PhysicalFileSystemProvider {
public MetadataFileSystemProvider(string rootFolder)
: base(rootFolder) {
}
protected internal virtual string MapPath(string virtualPath) {
return System.Web.Hosting.HostingEnvironment.MapPath(virtualPath);
}
Dictionary<string, string> ExtensionsDisplayName {
get {
return new Dictionary<string, string>() {
{ ".txt", "Text Document (.txt)" },
{ ".rtf", "Rich Text Format (.rtf)" },
{ ".xml", "XML Document (.xml)" },
{ ".zip", "Compressed (zipped) Folder (.zip)" }
};
}
}
public override IEnumerable<FileManagerFile> GetFiles(FileManagerFolder folder) {
List<FileManagerFile> result = new List<FileManagerFile>();
foreach(FileManagerFile file in base.GetFiles(folder)) {
var fileInfo = new FileInfo(MapPath(file.FullName));
FileManagerFileProperties fileProperties = new FileManagerFileProperties() {
Metadata = new Dictionary<string, object>()
};
FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo(MapPath(file.FullName));
var version = myFileVersionInfo.FileVersion;
string description = myFileVersionInfo.FileDescription;
fileProperties.Metadata.Add("Name", file.Name);
fileProperties.Metadata.Add("Type", ExtensionsDisplayName.ContainsKey(file.Extension) ? ExtensionsDisplayName[file.Extension]
: string.Format("{0} File ({1})", file.Extension.Replace(".", "").ToUpper(), file.Extension));
fileProperties.Metadata.Add("Size", fileInfo.Length.ToString("#,#") + " bytes");
fileProperties.Metadata.Add("Created", fileInfo.CreationTime.ToString("U"));
fileProperties.Metadata.Add("Modified", fileInfo.LastWriteTime.ToString("U"));
fileProperties.Metadata.Add("Accessed", fileInfo.LastAccessTime.ToString("U"));
fileProperties.Metadata.Add("Attributes", fileInfo.Attributes);
fileProperties.Metadata.Add("Description", description);
result.Add(new FileManagerFile(this, folder, file.Name, file.Id, fileProperties));
}
return result;
}
public override IEnumerable<FileManagerFolder> GetFolders(FileManagerFolder parentFolder) {
List<FileManagerFolder> result = new List<FileManagerFolder>();
foreach(FileManagerFolder folder in base.GetFolders(parentFolder)) {
var folderInfo = new FileInfo(MapPath(folder.FullName));
FileManagerFolderProperties folderProperties = new FileManagerFolderProperties() {
Metadata = new Dictionary<string, object>()
};
var folderSecurity = File.GetAccessControl(MapPath(folder.FullName));
folderProperties.Metadata.Add("Name", folder.Name);
folderProperties.Metadata.Add("Type", "Folder");
var directoryInfo = new DirectoryInfo(MapPath(folder.FullName));
var filesInfo = directoryInfo.GetFiles("*", SearchOption.AllDirectories);
long folderSize = 0;
foreach (var info in filesInfo)
folderSize += info.Length;
var filesCount = filesInfo.Length;
var subDirectoriesCount = directoryInfo.GetDirectories("*", SearchOption.AllDirectories).Length;
folderProperties.Metadata.Add("Size", folderSize.ToString("#,#") + " bytes");
folderProperties.Metadata.Add("Contains", string.Format("Files: {0}, Folders: {1}", filesCount, subDirectoriesCount));
folderProperties.Metadata.Add("Created", folderInfo.CreationTime.ToString("U"));
folderProperties.Metadata.Add("Modified", folderInfo.LastWriteTime.ToString("U"));
folderProperties.Metadata.Add("Accessed", folderInfo.LastAccessTime.ToString("U"));
folderProperties.Metadata.Add("Attributes", folderInfo.Attributes);
result.Add(new FileManagerFolder(this, parentFolder, folder.Name, folder.Id, folderProperties));
}
return result;
}
}