public static FileBrowseResult BrowsePath(string FullPath, List<string> Filters, bool getMediaDuration)
        {
            // Libraries
            if (FullPath.Equals("VIDEO_LIBRARY")) return GetFoldersForLibrary("videos", Filters);
            if (FullPath.Equals("DOCUMENTS_LIBRARY")) return GetFoldersForLibrary("documents", Filters);
            if (FullPath.Equals("MUSIC_LIBRARY")) return GetFoldersForLibrary("music", Filters);
            if (FullPath.Equals("PICTURES_LIBRARY")) return GetFoldersForLibrary("pictures", Filters);

            // 'Faux' library (collection)
            if (FullPath.Equals("MOVIE_LIBRARY")) return GetMoviesInMovieLibrary();

            FileBrowseResult output = new FileBrowseResult();

            output.BaseDirectory = FullPath;

            // Exists
            if (! Directory.Exists(FullPath))
            {
                output.ErrorText = "Directory not found.";
                output.Success = false;
                return output;
            }

            if (Filters.Count < 1) Filters = new List<string>() {"*.*"};

            DirectoryInfo masterDi = new DirectoryInfo(FullPath);

            // 1. Files
            List<FileInfo> tempOutputFiles = new List<FileInfo>();
            foreach (string filter in Filters)
                tempOutputFiles.AddRange(masterDi.GetFiles(filter));

            // Sort by name
            var orderedFiles = tempOutputFiles.OrderBy(f => f.Name);
            if (getMediaDuration) CreateShellHelperIfNull();  // use a shell helper to get duration of media files
            foreach (FileInfo fi in orderedFiles)
                output.Files.Add(fileInfoToBrowseItem(fi, getMediaDuration, false));
            sHelper = null;

            // 2. Directories
            DirectoryInfo[] directoryInfos = masterDi.GetDirectories();
            var orderedDirectories = directoryInfos.OrderBy(d => d.Name);
            foreach (DirectoryInfo di in orderedDirectories)
                output.Directories.Add( directoryInfoToBrowseItem(di, Filters));

            // Success
            output.Success = true;
            output.ErrorText = "OK";
            return output;
        }
        static string HTMLTableForVideoLibrary(FileBrowseResult fbrs, int numberOfColumns, int pageNumber, int itemsPerPage, bool showThumbnails)
        {
            List<string> content = new List<string>();

            foreach (BrowseItem strFolder in fbrs.Directories)
            {
                string cellContent = "";

                // Link
                string folderPath = Path.Combine(fbrs.BaseDirectory, strFolder.Name);
                folderPath = Functions.EncodeToBase64(folderPath);

                string folderImageSource = "/static/images/imgFolder150x75.png";
                HTMLImage image = new HTMLImage(folderImageSource, "folderpic");
                cellContent += image.ToString();
                cellContent += "<br />";
                cellContent += Path.GetFileName(strFolder.Name);

                HTMLLink lnk = new HTMLLink("browsevideos?PATH=" + folderPath, cellContent);

                content.Add(lnk.ToString());
            }
            foreach (BrowseItem strFile in fbrs.Files)
            {
                // Assemble path to file
                string filePath = Path.Combine(fbrs.BaseDirectory, strFile.Name);
                filePath = Functions.EncodeToBase64(filePath);

                string imgSrc = "getfilethumbnail64?filename=" + filePath + "&size=medium";
                HTMLImage image = new HTMLImage(imgSrc, "thumbnail");

                // Link
                HTMLLink lnk = new HTMLLink("streamvideo?FN=" + filePath, image.ToString());
                content.Add(lnk.ToString());
            }

            return HTMLTable.HTMLTableWithCellContents("videolibrarytable", numberOfColumns, content);
        }
        // music, videos, pictures, documents
        static FileBrowseResult GetFoldersForLibrary(string libraryName, List<string> Filters)
        {
            FileBrowseResult output = new FileBrowseResult();

            CreateShellHelperIfNull();

            try
            {

                List<String> folders  = new List<string>();
                folders = FoldersForLibrary(libraryName);

                foreach (string folder in folders)
                {
                    BrowseItem folderItem = stringToBrowseItem(folder, true, Filters);
                    if (folderItem != null) output.Directories.Add(folderItem);
                }

                output.ErrorText = "OK";
                output.Success = true;
            }
            catch (ArgumentException )
            {
                output.Success = false;
                output.ErrorText = "NO LIBRARY";
            }
            catch (Exception ex)
            {
                output.Success = false;
                output.ErrorText = ex.Message;
            }

            sHelper = null;
            return output;
        }
        /// <summary>
        /// Retrieve the files in all registered 7MC movie library folders, with extensions from Settings.Default.VideoFileExtensions
        /// </summary>
        /// <returns></returns>
        static FileBrowseResult GetMoviesInMovieLibrary()
        {
            FileBrowseResult output = new FileBrowseResult();

            CreateShellHelperIfNull();

            output.Directories = new List<BrowseItem>();

            MCLibraryFolderHelper fHelper = new MCLibraryFolderHelper();
            List<string> movieFolders = fHelper.MediaCenterLibraryFolders(MCLibraryFolderHelper.Libraries.Movie);

            List<string> VideoFilters = filtersForMediaType(MediaFileTypes.Video);
            List<BrowseItem> filesFound = new List<BrowseItem>();
            foreach (string movieFolder in movieFolders)
            {
                browseFolderForFiles(movieFolder, ref filesFound, VideoFilters, true);
            }

            // Now add recorded TV shows that are movies
            foreach (TVProgramme tvp in RecTV.Default.RecordedTVProgrammes.Values)
            {
                if (tvp.ProgramType != TVProgrammeType.Movie) continue;  // movies only

                FileInfo fi = new FileInfo(tvp.Filename);
                BrowseItem newItem = fileInfoToBrowseItem(fi, true, true);
                filesFound.Add(newItem);
            }

            // Sort the list of movies alphabetically by filename (NAME not file path, path is stripped away by the comparer)
            CommonEPG.Comparers.BrowseItemComparer bComparer = new CommonEPG.Comparers.BrowseItemComparer();
            filesFound.Sort(bComparer);
            output.Files = filesFound;

            // Set base directory flag
            output.BaseDirectory = "MOVIE_LIBRARY";
            output.Success = true;

            sHelper = null;

            return output;
        }
        public static bool SendFolderFilesAsZipFile(FileBrowseResult fbResult, ref BrowserSender bSender)
        {
            // We'll need a shell helper
            CreateShellHelperIfNull();

            // Set up temp directory
            string tempFolderName = Path.GetRandomFileName();
            string tempPath = Path.Combine(Functions.ZipTempFolder, tempFolderName);
            Directory.CreateDirectory(tempPath);

            // Any files?
            if (fbResult.Files.Count < 1) return false;

            List<string> outputFiles = new List<string>();
            foreach (BrowseItem bItem in fbResult.Files)
            {
                string strFullPath = Path.Combine(fbResult.BaseDirectory, bItem.Name);
                outputFiles.Add(strFullPath);
            }

            // Now zip up the files
            string strOutputZipFile = Path.Combine(Functions.ZipTempFolder, (Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) + ".zip"));
            bool result = ZipHelper.CreateZipFileFromFiles(outputFiles, strOutputZipFile);

            // And send the zip file to the browser
            result &= (bSender.SendFileToBrowser(strOutputZipFile, false, false, true));
            File.Delete(strOutputZipFile);
            Directory.Delete(tempPath, true);

            return result;
        }