示例#1
0
        public override bool[] Share(IElementoNube elemento, bool notify = true, string message = null, SharingLevel level = SharingLevel.ViewerNoComment, params string[] emailsUsersToShare)
        {
            bool[] shared = new bool[emailsUsersToShare.Length];
            List <FileMemberActionResult> results;

            Dropbox.Api.Sharing.AddMember[]      membersFolder;
            Dropbox.Api.Sharing.MemberSelector[] membersFile;
            Dropbox.Api.Sharing.AccessLevel      shareLevel = GetShareLevel(level);
            if (elemento.IsAFolder)
            {
                membersFolder = new Dropbox.Api.Sharing.AddMember[emailsUsersToShare.Length];
                for (int i = 0; i < membersFolder.Length; i++)
                {
                    membersFolder[i] = new Dropbox.Api.Sharing.AddMember(new Dropbox.Api.Sharing.MemberSelector.Email(emailsUsersToShare[i]), shareLevel);
                }
                client.Sharing.AddFolderMemberAsync(GetIdShareFolder(elemento), membersFolder, notify, message).Wait();
            }
            else
            {
                membersFile = new MemberSelector[emailsUsersToShare.Length];
                for (int i = 0; i < membersFile.Length; i++)
                {
                    membersFile[i] = new MemberSelector.Email(emailsUsersToShare[i]);
                }
                results = client.Sharing.AddFileMemberAsync(elemento.PathNube, membersFile, message, notify, shareLevel).Result;
                for (int i = 0; i < results.Count; i++)
                {
                    shared[i] = results[i].Result.IsSuccess;
                }
            }
            return(shared);
        }
        public static void HandleFolderCreationAndSharing(string folderPath, string emailAddress)
        {
            // GET Dropbox oauth2AccessToken from the Dropbox app you create.
            var dropboxClient = new Dropbox.Api.DropboxClient("");

            FolderMetadata folderData;

            // Try to Get folder
            try
            {
                var folders = dropboxClient.Files.ListFolderAsync(folderPath, true).Result;
                folderData = folders.Entries[0].AsFolder;
            }
            catch
            {
                // Create the folder if not exist
                folderData = dropboxClient.Files.CreateFolderAsync(folderPath).Result;
            }

            string shareId = folderData.SharedFolderId;

            //Initial Share if not sharing enabled on the folder
            //This only shares the folder with the Dropbox owner
            if (folderData.SharedFolderId == null)
            {
                shareId = dropboxClient.Sharing.ShareFolderAsync(folderPath).Result.AsComplete.Value.SharedFolderId;
            }


            MemberSelector.Email mailMember = new MemberSelector.Email(emailAddress);
            AddMember            addMember  = new AddMember(mailMember, AccessLevel.Editor.Instance);

            AddFolderMemberArg args2 = new AddFolderMemberArg(shareId, new List <AddMember>()
            {
                addMember
            }, false, "This is a message sent from the app trial");

            dropboxClient.Sharing.AddFolderMemberAsync(args2).Wait();
        }