/// <summary>
        /// Retrieves the content of a given folder.
        /// </summary>
        /// <param name="path">The folder's path, which content will be served.</param>
        /// <returns>A <see cref="JsonResult"/> containing folder's files and child folders.</returns>
        /// <exception cref="HttpException">Throws 403 Forbidden if the supplied <paramref name="path"/> is outside of the valid paths.</exception>
        /// <exception cref="HttpException">Throws 404 File Not Found if refered folder does not exist.</exception>
        public virtual JsonResult Browse(string path)
        {
            path = NormalizePath(path);

            if (AuthorizeBrowse(path))
            {
                try
                {
                    directoryBrowser.Server = Server;

                    var result = new BrowseResult
                    {
                        Files        = directoryBrowser.GetFiles(path, Filter),
                        Directories  = directoryBrowser.GetDirectories(path),
                        Path         = pathProvider.AppendTrailingSlash(path),
                        ContentPaths = ContentPaths.Select(root => pathProvider.ToAbsolute(root)).ToArray()
                    };

                    return(Json(result));
                }
                catch (DirectoryNotFoundException)
                {
                    throw new HttpException(404, "File Not Found");
                }
            }

            throw new HttpException(403, "Forbidden");
        }
Ejemplo n.º 2
0
        public virtual JsonResult Read(string path)
        {
            var fullPath = NormalizePath(path);

            if (AuthorizeRead(fullPath))
            {
                try
                {
                    var files       = directoryBrowser.GetFiles(fullPath, Filter);
                    var directories = directoryBrowser.GetDirectories(fullPath);
                    var result      = files.Concat(directories);

                    return(Json(result.ToArray()));
                }
                catch (DirectoryNotFoundException)
                {
                    throw new Exception("File Not Found");
                }
            }

            throw new Exception("Forbidden");
        }
Ejemplo n.º 3
0
        public virtual JsonResult Read(string path)
        {
            path = NormalizePath(path);

            if (AuthorizeRead(path))
            {
                try
                {
                    directoryBrowser.Server = Server;

                    var result = directoryBrowser.GetFiles(path, Filter)
                                 .Concat(directoryBrowser.GetDirectories(path));

                    return(Json(result));
                }
                catch (DirectoryNotFoundException)
                {
                    throw new HttpException(404, "File Not Found");
                }
            }

            throw new HttpException(403, "Forbidden");
        }