Esempio n. 1
0
        // TODO: Clean up and refactor
        private void CreateControlHierarchy()
        {
            Index = 0;
            if (BaseUrl != null)
            {
                BasePath = System.Web.HttpContext.Current.Server.MapPath(BaseUrl.ToString());
            }
            string path = BasePath + Folder;

            // Prevent hacking
            if (path.Substring(0, BasePath.Length).ToUpperInvariant() != BasePath.ToUpperInvariant())
            {
                path = BasePath;
            }
            Folder = path.Substring(BasePath.Length - 1);

            DirectoryInfo dir = new DirectoryInfo(path);

            if (dir.Exists)
            {
                // Lägg till parentlänk
                if (path.Length != BasePath.Length)
                {
                    CreateItem(new FileSystemObject("..", 0, 0), FolderTemplate);
                    Index++;
                }

                DirectoryInfo[]         folders    = dir.GetDirectories();
                List <FileSystemObject> folderList = (from folder in folders
                                                      where !folder.Name.StartsWith("_") && !folder.Name.StartsWith(".")
                                                      select
                                                      new FileSystemObject(folder.Name, 0, 0,
                                                                           FileSystemObject.GetFolderFriendlyName(
                                                                               folder))).ToList();

                //Sortera folders på friendly name
                IComparer <FileSystemObject> comparer = new FileSystemObjectComparer();
                folderList.Sort(comparer);
                //Lägg till dom
                foreach (FileSystemObject folderItem in folderList)
                {
                    CreateItem(folderItem, FolderTemplate);
                    Index++;
                }

                FileInfo[]       files = dir.GetFiles();
                FileInfoComparer cpfi  = new FileInfoComparer {
                    SortDirection = SortDirection, SortOrder = SortOrder
                };
                Array.Sort(files, cpfi);
                foreach (FileInfo file in files)
                {
                    CreateItem(new FileSystemObject(file.Name, 1, file.Length), FileTemplate);
                    Index++;
                    if (MaxCount != 0 && MaxCount == Index)
                    {
                        break;
                    }
                }
            }
        }
Esempio n. 2
0
        // TODO: Clean up and refactor
        private void CreateControlHierarchy() {
            Index = 0;
            if (BaseUrl != null) BasePath = System.Web.HttpContext.Current.Server.MapPath(BaseUrl.ToString());
            string path = BasePath + Folder;

            // Prevent hacking
            if (path.Substring(0, BasePath.Length).ToUpperInvariant() != BasePath.ToUpperInvariant()) {
                path = BasePath;
            }
            Folder = path.Substring(BasePath.Length - 1);

            DirectoryInfo dir = new DirectoryInfo(path);

            if (dir.Exists) {

                // Lägg till parentlänk
                if (path.Length != BasePath.Length) {
                    CreateItem(new FileSystemObject("..", 0, 0), FolderTemplate);
                    Index++;
                }

                DirectoryInfo[] folders = dir.GetDirectories();
                List<FileSystemObject> folderList = (from folder in folders
                                                     where !folder.Name.StartsWith("_") && !folder.Name.StartsWith(".")
                                                     select
                                                         new FileSystemObject(folder.Name, 0, 0,
                                                                              FileSystemObject.GetFolderFriendlyName(
                                                                                  folder))).ToList();

                //Sortera folders på friendly name
                IComparer<FileSystemObject> comparer = new FileSystemObjectComparer();
                folderList.Sort(comparer);
                //Lägg till dom
                foreach (FileSystemObject folderItem in folderList) {
                    CreateItem(folderItem, FolderTemplate);
                    Index++;
                }

                FileInfo[] files = dir.GetFiles();
                FileInfoComparer cpfi = new FileInfoComparer {SortDirection = SortDirection, SortOrder = SortOrder};
                Array.Sort(files, cpfi);
                foreach (FileInfo file in files) {
                    CreateItem(new FileSystemObject(file.Name, 1, file.Length), FileTemplate);
                    Index++;
                    if (MaxCount != 0 && MaxCount == Index)
                        break;
                }
            }
        }