Need to see if your shared folder is taking up space on your dropbox 👨💻? Find out how to check here.
Forum Discussion
VAR_46
10 years agoHelpful | Level 6
How we share folder and file ?, via dropbox api
okay i start from scratch "again", how i can share file and folder via dropbox api, i think some sharing flow, 1. get the file and folder id, ( i already try it, show just two digit number) 2. c...
Greg-DB
Dropbox Community Moderator
10 years agoTo share a folder, you should first call ShareFolderAsync. That takes a "path" parameter that should be the path to the folder that you want to share. The documentation explains how to check the result of that operation.
Once that's done, you should then call AddFolderMemberAsync to invite members to that shared folder. That takes the shared folder ID, from the first step above, as well as the list of members you want to invite (a list of AddMember instances).
That would look something like this:
var shareFolderLaunch = await this.client.Sharing.ShareFolderAsync ("/folder_to_share");
var sharedFolderId = "";
if (shareFolderLaunch.IsAsyncJobId) {
while (true) {
var shareFolderJobStatus = await this.client.Sharing.CheckShareJobStatusAsync(shareFolderLaunch.AsAsyncJobId.Value);
if (shareFolderJobStatus.IsFailed) {
Console.WriteLine ("Sharing folder failed: " + shareFolderJobStatus.AsFailed.Value);
return;
} else if (shareFolderJobStatus.IsInProgress) {
Console.WriteLine ("Sharing folder in progress...");
// todo: add some delay
} else if (shareFolderJobStatus.IsComplete) {
Console.WriteLine ("Sharing folder complete.");
sharedFolderId = shareFolderJobStatus.AsComplete.Value.SharedFolderId;
break;
}
}
} else if (shareFolderLaunch.IsComplete) {
sharedFolderId = shareFolderLaunch.AsComplete.Value.SharedFolderId;
} else {
return;
}
Console.WriteLine ("Shared folder with ID: " + sharedFolderId);
var members = new[] { new AddMember(new MemberSelector.Email("email@example.com")) };
await this.client.Sharing.AddFolderMemberAsync(sharedFolderId, members);VAR_46
10 years agoHelpful | Level 6
hey @Greg , thanks for the code now i able to share a folder, but i think the next step is to mount the folder at the added member, i want to do it automaticly from sharing can i ?
- Greg-DB10 years ago
Dropbox Community Moderator
Yes, as long as you're authorized as the receiving user you can use MountFolderAsync to mount the shared folder in their account.
- VAR_4610 years agoHelpful | Level 6
okay, i get it but how to get the share id is it the same way like we share the folder or i just need to use asyncidjob is complete ?, and why when i try to share file "add member selector "method that you gave to me is not working, its always return with null. and how to change its level of acces
this my code
Private Async Sub ShareFileToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ShareFileToolStripMenuItem.Click For Each C As ListViewItem In listfile.SelectedItems Dim sharefile = A.Sharing.GetFileMetadataAsync(direktori.Text & "/" & C.Text) Dim sharefileid = sharefile.Result.Id MessageBox.Show(sharefileid) Dim member = {New AddMember(New MemberSelector.Email("vincencia.ratna@gmail.com"))} Await A.Sharing.AddFileMemberAsync(file:=sharefileid, members:=member) Next End Suband the next question is how we change folder member policy ?
- Greg-DB10 years ago
Dropbox Community Moderator
The MountFolderAsync method takes a shared folder ID, which is the same as the sharedFolderId value from my code sample.
You can also use ListMountableFoldersAsync/ListMountableFoldersContinueAsync to list the folders available to mount in an account.
Your latest sample instead seems to just be getting the ID of a file, not a shared folder ID. Also, it appears you're trying to use AddFileMemberAsync, which is different from AddFolderMemberAsync anyway.
The AddFileMemberAsync method does take a file path or ID. Here's a sample for AddFileMemberAsync that works for me:
var members = new[] { new MemberSelector.Email("email@example.com") }; await client.Sharing.AddFileMemberAsync ("/test.txt", members);What specifically wasn't working for you? One thing I notice that may be a problem in your code is that you're building an array of AddMember, but AddFileMemberAsync just takes an array of MemberSelector.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!