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. choose the folder to share by adding member ( using id but i'm not sure the metadata.id.tostring give the right id)
3. what i shoul do next ?
step 1
using get_metadata -> should i call sharedfolderasync ? -> what next ? -> using addfoldermember -> done ?
step 2
using get_metadata -> addfoldermember -> done
betwen step 1 or 2 , which one is right ?
9 Replies
- Greg-DB10 years ago
Dropbox Community Moderator
To 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_4610 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.
- VAR_4610 years agoHelpful | Level 6
okay greg, your code work, now my problem is why i cant share mp3 ? , are there some file format that dropbox api doesnt support to share ?, and now i stil try to show the list of mountable folder, and mount it as reciever. i confuse how to retrieve the list. this is the las feature of my basic dropbox vb application, i interested to upgrade my application further with more robust API.
now the question is
1. what file extension dropbox support to add member beside txt ?
2. how to get the list of mountable folder -> get the share id -> and mount it
- Greg-DB10 years ago
Dropbox Community Moderator
1) The file extension doesn't matter. You can share any file type. Are you getting an error when trying to share a different file?
2) You can use ListMountableFoldersAsync/ListMountableFoldersContinueAsync to list the folders available to mount in an account. You can then use MountFolderAsync to mount folders using the returned SharedFolderMetadata.SharedFolderId.
- VAR_4610 years agoHelpful | Level 61. Hi greg, when i try to add member to a jpg file it's return with dropbox api exception 1, is it some thing wrong or i must use share link ?.
2. Yes i know, the ricght code is listmountablefolderasync but the code i still confuse how to implement at code a cause this list is different with listfile async - Greg-DB10 years ago
Dropbox Community Moderator
1. What exception are you getting specifically?
2. What do you have so far? What are you stuck on?
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!