public async Task <string> GetSharedLink(string path)
    {
        try
        {
            path = CompletePath(path);
            var settings           = new SharedLinkSettings();
            var sharedLinkMetadata = await DBClient.Sharing.ListSharedLinksAsync(path);

            var links = sharedLinkMetadata.Links;

            string pathLower = path.ToLower();

            foreach (var link in links)
            {
                if (link.PathLower.Equals(pathLower))
                {
                    return(link.Url);
                }
            }

            return(null);
        }
        catch (Exception)
        {
            return(null);
        }
    }
        public static async Task <SharedLinkMetadata> CreateFileShareLink(DropboxClient client, Metadata file, RequestedVisibility requestedVisibility, string password)
        {
            SharedLinkSettings settings = new SharedLinkSettings();

            if (requestedVisibility.IsPassword)
            {
                if (password == null)
                {
                    //TODO: Add error handling
                    return(new SharedLinkMetadata());
                }
                settings = new SharedLinkSettings(requestedVisibility, password);
            }
            else
            {
                settings = new SharedLinkSettings(requestedVisibility);
            }

            CreateSharedLinkWithSettingsArg arg = new CreateSharedLinkWithSettingsArg(file.PathLower, settings);

            try
            {
                return(await client.Sharing.CreateSharedLinkWithSettingsAsync(arg));
            }
            catch (ApiException <CreateSharedLinkWithSettingsError> error)
            {
                //TODO: Add error handling
                return(new SharedLinkMetadata());
            }
        }
        public static async Task <SharedLinkMetadata> ChangeShareLinkPermissions(DropboxClient client, string url, RequestedVisibility requestedVisibility)
        {
            SharedLinkSettings settings = new SharedLinkSettings(requestedVisibility);

            try
            {
                return(await client.Sharing.ModifySharedLinkSettingsAsync(url, settings));
            }
            catch (ApiException <ModifySharedLinkSettingsError> error)
            {
                //TODO: Add error handling
                return(new SharedLinkMetadata());
            }
        }
    public async Task <string> CreateSharedLink(string path)
    {
        try
        {
            path = CompletePath(path);
            var settings           = new SharedLinkSettings();
            var sharedLinkMetadata = await DBClient.Sharing.CreateSharedLinkWithSettingsAsync(path, settings);

            return(sharedLinkMetadata.Url);
        }
        catch (Exception)
        {
            return(null);
        }
    }
        /// <summary>
        /// <para>Begins an asynchronous send to the create shared link with settings
        /// route.</para>
        /// </summary>
        /// <param name="path">The path to be shared by the shared link</param>
        /// <param name="settings">The requested settings for the newly created shared
        /// link</param>
        /// <param name="callback">The method to be called when the asynchronous send is
        /// completed.</param>
        /// <param name="callbackState">A user provided object that distinguished this send
        /// from other send requests.</param>
        /// <returns>An object that represents the asynchronous send request.</returns>
        public sys.IAsyncResult BeginCreateSharedLinkWithSettings(string path,
                                                                  SharedLinkSettings settings = null,
                                                                  sys.AsyncCallback callback = null,
                                                                  object callbackState = null)
        {
            var createSharedLinkWithSettingsArg = new CreateSharedLinkWithSettingsArg(path,
                                                                                      settings);

            return this.BeginCreateSharedLinkWithSettings(createSharedLinkWithSettingsArg, callback, callbackState);
        }
        /// <summary>
        /// <para>Create a shared link with custom settings. If no settings are given then the
        /// default visibility is <see cref="Dropbox.Api.Sharing.RequestedVisibility.Public" />
        /// (The resolved visibility, though, may depend on other aspects such as team and
        /// shared folder settings).</para>
        /// </summary>
        /// <param name="path">The path to be shared by the shared link</param>
        /// <param name="settings">The requested settings for the newly created shared
        /// link</param>
        /// <returns>The task that represents the asynchronous send operation. The TResult
        /// parameter contains the response from the server.</returns>
        /// <exception cref="Dropbox.Api.ApiException{TError}">Thrown if there is an error
        /// processing the request; This will contain a <see
        /// cref="CreateSharedLinkWithSettingsError"/>.</exception>
        public t.Task<SharedLinkMetadata> CreateSharedLinkWithSettingsAsync(string path,
                                                                            SharedLinkSettings settings = null)
        {
            var createSharedLinkWithSettingsArg = new CreateSharedLinkWithSettingsArg(path,
                                                                                      settings);

            return this.CreateSharedLinkWithSettingsAsync(createSharedLinkWithSettingsArg);
        }
        /// <summary>
        /// <para>Begins an asynchronous send to the modify shared link settings route.</para>
        /// </summary>
        /// <param name="url">URL of the shared link to change its settings</param>
        /// <param name="settings">Set of settings for the shared link.</param>
        /// <param name="callback">The method to be called when the asynchronous send is
        /// completed.</param>
        /// <param name="callbackState">A user provided object that distinguished this send
        /// from other send requests.</param>
        /// <returns>An object that represents the asynchronous send request.</returns>
        public sys.IAsyncResult BeginModifySharedLinkSettings(string url,
                                                              SharedLinkSettings settings,
                                                              sys.AsyncCallback callback,
                                                              object callbackState = null)
        {
            var modifySharedLinkSettingsArgs = new ModifySharedLinkSettingsArgs(url,
                                                                                settings);

            return this.BeginModifySharedLinkSettings(modifySharedLinkSettingsArgs, callback, callbackState);
        }
        /// <summary>
        /// <para>Modify the shared link's settings.</para>
        /// <para>If the requested visibility conflict with the shared links policy of the team
        /// or the shared folder (in case the linked file is part of a shared folder) then the
        /// <see cref="Dropbox.Api.Sharing.LinkPermissions.ResolvedVisibility" /> of the
        /// returned <see cref="SharedLinkMetadata" /> will reflect the actual visibility of
        /// the shared link and the <see
        /// cref="Dropbox.Api.Sharing.LinkPermissions.RequestedVisibility" /> will reflect the
        /// requested visibility.</para>
        /// </summary>
        /// <param name="url">URL of the shared link to change its settings</param>
        /// <param name="settings">Set of settings for the shared link.</param>
        /// <returns>The task that represents the asynchronous send operation. The TResult
        /// parameter contains the response from the server.</returns>
        /// <exception cref="Dropbox.Api.ApiException{TError}">Thrown if there is an error
        /// processing the request; This will contain a <see
        /// cref="ModifySharedLinkSettingsError"/>.</exception>
        public t.Task<SharedLinkMetadata> ModifySharedLinkSettingsAsync(string url,
                                                                        SharedLinkSettings settings)
        {
            var modifySharedLinkSettingsArgs = new ModifySharedLinkSettingsArgs(url,
                                                                                settings);

            return this.ModifySharedLinkSettingsAsync(modifySharedLinkSettingsArgs);
        }