cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Are you an educator? Well we want to hear from you, so check out some tools we think might help you out here!

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Check if folder exists and collect shared folder

Check if folder exists and collect shared folder

Nenciu D.
New member | Level 1

Hello,

1.I'm trying to check if folder exist in my dropbox by retrieving metadata from given path: (example path "/myfolder")

public async Task<Metadata> GetFolderMetadata(string folderPath)
{
Metadata folderMetadata = await client.Files.GetMetadataAsync(folderPath);
if (folderMetadata != null)
return folderMetadata;

return null;
}

This is my method ,but if path doesn't exist , my application crashes without any error message.

2.Also I want to collect all shared folders and then to retrieve the users(their emails only) that are sharing that folders.

I'm using sdk v2 for C#.

Thank you 

5 Replies 5

Re: Check if folder exists and collect shared folder

Steve M.
Dropboxer

I believe you'll need to wrap the call in a try/catch so you can handle the exception when the path doesn't exist.

For your second question, this isn't possible in the API today. (The email addresses of members of a shared folder are not exposed.)

Re: Check if folder exists and collect shared folder

Nenciu D.
New member | Level 1

Thank you again Steve , you are great . So my solution for the first question was something like this:

private bool CheckIfCloudPathExists(string cloudPath)
{
Metadata metadata = new Metadata();
try
{
System.Threading.Tasks.Task<Metadata> taskUpload = Task.Run(() => GetFolderMetadata(cloudPath));
if (taskUpload.Result != null)
metadata = taskUpload.Result;
}
catch (AggregateException e)
{
if (e != null && e.InnerException != null && e.InnerException is ApiException<GetMetadataError>)
{
GetMetadataError err = (e.InnerException as ApiException<GetMetadataError>).ErrorResponse;
if (err.IsNotFound || err.IsOther)
return false;
}
}
return metadata != null;
}

I will reformulate the second question : Is it possible to set permisions to a file like this :

File cloudFile = GetCloudFile(CloudPath); //here I'm getting my file ,and then I set it's permissions
if (cloudFile == null)
return false;

Permission newPermission = new Permission();
newPermission.Value = UserEmail;
newPermission.Type = "user";

if ( PermissionType == 1 )
newPermission.Role = "reader";
else if (PermissionType == 2)
newPermission.Role = "writer";

try
{
PermissionsResource.InsertRequest insertRequest = GoogleDriveService.Permissions.Insert(newPermission, cloudFile.Id);

if (NotifyUserByEmail == false && UserEmail.EndsWith("@google.com"))
insertRequest.SendNotificationEmails = true;
else
insertRequest.SendNotificationEmails = NotifyUserByEmail;

if (!string.IsNullOrEmpty(OptionalEmailMessage))
insertRequest.EmailMessage = OptionalEmailMessage;

var retVal = insertRequest.Execute();
}

This example is made on google api . When I want to share a file , I set it's permissions.

 

Re: Check if folder exists and collect shared folder

Steve M.
Dropboxer

Dropbox doesn't have a permission model that looks like that. In Dropbox, you can create a share link for a file or folder (which can then be used by anyone who has that URL to read the contents of the file or folder), or you can share a folder (which gives specific users access to that folder in their own Dropbox).

Currently, the API only supports share links. So you can get a link for a file and then send that link to people you want to grant (read-only) access to.

Re: Check if folder exists and collect shared folder

Nenciu D.
New member | Level 1

The Share Folder button method or Send link method for a file are implemented? Because I want to at least send a notification through email .

 

Re: Check if folder exists and collect shared folder

Greg-DB
Dropboxer

The SDK enables you to get a shared link for a file or folder, e.g., using CreateSharedLinkAsync.

It doesn't currently offer the ability to create shared folders though, as Steve mentioned.

In any case, it's not currently possible to make Dropbox send an email about it for you via the API, but I'll be sure to pass this along as a feature request.

Poll
We love to learn from the educators who use Dropbox. Whether you teach kids, teens, adults or a combination of all three, we want to know what apps and integrations you use with Dropbox to help with teaching. Which of the ones below is your favorite, or most used tool?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropboxer
  • User avatar
    Nenciu D. New member | Level 1
  • User avatar
    Steve M. Dropboxer
What do Dropbox user levels mean?
Need more support?