public async Task TestPathRoot()
        {
            await Client.Files.UploadAsync("/Foo.txt", body : GetStream("abc"));

            var pathRootClient = Client.WithPathRoot(PathRoot.Home.Instance);
            var metadata       = await pathRootClient.Files.GetMetadataAsync("/Foo.txt");

            Assert.AreEqual("/foo.txt", metadata.PathLower);

            pathRootClient = Client.WithPathRoot(new PathRoot.Root("123"));

            var exceptionRaised = false;

            try
            {
                await pathRootClient.Files.GetMetadataAsync("/Foo.txt");
            }
            catch (PathRootException e)
            {
                exceptionRaised = true;
                var error = e.ErrorResponse;
                Assert.IsTrue(error.IsInvalidRoot);
                Assert.IsTrue(error.AsInvalidRoot.Value.IsUser);
            }

            Assert.IsTrue(exceptionRaised);
        }
        public async Task <GetResponse <string> > CreateShareFolderLinkAsync(string folderName, string description)
        {
            var response = new GetResponse <string>();

            try
            {
                // Create Client
                using (var client = new DropboxClient(_auditConfiguration.ShareFileConfiguration.Token))
                {
                    var account = await client.Users.GetCurrentAccountAsync();

                    var clientWitRoot = client.WithPathRoot(new PathRoot.Root(account.RootInfo.RootNamespaceId));

                    var fullpath = $@"/Audit Files/{folderName}";

                    // Create Folder
                    var folder = await clientWitRoot.Files.CreateFolderV2Async(fullpath, true);

                    // Create link
                    var link = await clientWitRoot.Sharing.CreateSharedLinkWithSettingsAsync(fullpath);

                    response.Content = link.Url;
                }
            }
            catch (Exception e)
            {
                _logManager.LogError(e, "FileShareProviderDropbox.CreateShareLinkAsync");
                response.AddError(e);
            }

            return(response);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Lists the items within a folder inside team space. See
        /// https://www.dropbox.com/developers/reference/namespace-guide for details about
        /// user namespace vs team namespace.
        /// </summary>
        /// <param name="client">The Dropbox client.</param>
        /// <param name="path">The path to list.</param>
        /// <returns>The <see cref="Task"/></returns>
        private async Task ListFolderInTeamSpace(DropboxClient client, string path)
        {
            // Fetch root namespace info from user's account info.
            var account = await client.Users.GetCurrentAccountAsync();

            if (!account.RootInfo.IsTeam)
            {
                Console.WriteLine("This user doesn't belong to a team with shared space.");
            }
            else
            {
                try
                {
                    // Point path root to namespace id of team space.
                    client = client.WithPathRoot(new PathRoot.Root(account.RootInfo.RootNamespaceId));
                    await ListFolder(client, path);
                }
                catch (PathRootException ex)
                {
                    Console.WriteLine(
                        "The user's root namespace ID has changed to {0}",
                        ex.ErrorResponse.AsInvalidRoot.Value);
                }
            }
        }