public MenuItem BuildMenuItem(Model.File file, MenuItem parentMenuItem) { MenuItem root = new MenuItem() { Title = file.FileName, parentItem = parentMenuItem }; return(root); }
public ObservableCollection <Model.File> GetAllFilesInDriveOrFolder(Drive drive, Folder folder) { ObservableCollection <Model.File> files = new ObservableCollection <Model.File>(); if (folder == null) { System.IO.DriveInfo di = new System.IO.DriveInfo(drive.DriveName + ":\\"); System.IO.DirectoryInfo dirInfo = di != null ? di.RootDirectory : null; DirectoryInfo[] dirInfoFolders = dirInfo != null?dirInfo.GetDirectories() : null; FileInfo[] fileInfo = dirInfo != null?dirInfo.GetFiles() : null; if (fileInfo != null && fileInfo.Length > 0) { foreach (FileInfo item in fileInfo) { FileAttributes attributes = item.Attributes; string attrNames = Convert.ToString(attributes); if (attrNames != null && !attrNames.Contains("Hidden")) { Model.File file = new Model.File(); file.FileName = item.Name; files.Add(file); } } } } else { try { string[] filesInFolder = Directory.GetFiles(folder.FolderPath); if (filesInFolder != null && filesInFolder.Length > 0) { foreach (string item in filesInFolder) { int folderPathLength = folder.FolderPath.Length; string fileInFolder = null; fileInFolder = item.Remove(0, folderPathLength + 1); Model.File file = new Model.File(); file.FileName = fileInFolder; file.FilePath = item; files.Add(file); } } } catch (Exception) { } } return(files); }