Example #1
0
        /// <summary>
        /// Delete the directory
        /// </summary>
        /// <param name="path">Path to the directory</param>
        /// <returns>A task that represents the completion of the operation</returns>
        protected virtual async Task DeleteDirectoryAsync(string path)
        {
            path = GetVirtualPath(path);
            if (path == GetRootDirectory())
            {
                throw new Exception(GetLanguageResource("E_CannotDeleteRoot"));
            }

            path = GetFullPath(path);
            if (!_fileProvider.DirectoryExists(path))
            {
                throw new Exception(GetLanguageResource("E_DeleteDirInvalidPath"));
            }

            if (_fileProvider.GetDirectories(path).Length > 0 || _fileProvider.GetFiles(path).Length > 0)
            {
                throw new Exception(GetLanguageResource("E_DeleteNonEmpty"));
            }

            try
            {
                _fileProvider.DeleteDirectory(path);
                await HttpContext.Response.WriteAsync(GetSuccessResponse());
            }
            catch
            {
                throw new Exception(GetLanguageResource("E_CannotDeleteDir"));
            }
        }