Example #1
0
        // https://www.dropbox.com/developers/core/docs#files_put
        public UploadResult UploadFile(Stream stream, string path, string fileName, bool createShareableURL = false, DropboxURLType urlType = DropboxURLType.Default)
        {
            if (!OAuth2Info.CheckOAuth(AuthInfo))
            {
                Errors.Add("Dropbox login is required.");
                return(null);
            }

            string url = URLHelpers.CombineURL(URLFiles, URLHelpers.URLPathEncode(path));

            // There's a 150MB limit to all uploads through the API.
            UploadResult result = UploadData(stream, url, fileName, headers: GetAuthHeaders());

            if (result.IsSuccess)
            {
                DropboxContentInfo content = JsonConvert.DeserializeObject <DropboxContentInfo>(result.Response);

                if (content != null)
                {
                    if (createShareableURL)
                    {
                        result.URL = CreateShareableLink(content.Path, urlType);
                    }
                    else
                    {
                        result.URL = GetPublicURL(content.Path);
                    }
                }
            }

            return(result);
        }
        public ListViewItem GetParentFolder(string currentPath)
        {
            if (!string.IsNullOrEmpty(currentPath))
            {
                string parentFolder = currentPath.Remove(currentPath.LastIndexOf('/'));

                DropboxContentInfo content = new DropboxContentInfo() { Icon = "folder", Is_dir = true, Path = parentFolder };

                ListViewItem lvi = new ListViewItem("..");
                lvi.ImageKey = ilm.AddImage(content.Icon);
                lvi.Tag = content;
                return lvi;
            }

            return null;
        }
Example #3
0
        // https://www.dropbox.com/developers/core/api#files-POST
        public UploadResult UploadFile(Stream stream, string path, string fileName, bool createShareableURL = false, bool shortURL = true)
        {
            if (!OAuthInfo.CheckOAuth(AuthInfo))
            {
                Errors.Add("Login is required.");
                return(null);
            }

            string url = Helpers.CombineURL(URLFiles, Helpers.URLPathEncode(path));

            Dictionary <string, string> args = new Dictionary <string, string>();

            args.Add("file", fileName);

            string query = OAuthManager.GenerateQuery(url, args, HttpMethod.Post, AuthInfo);

            // There's a 150MB limit to all uploads through the API.
            UploadResult result = UploadData(stream, query, fileName);

            if (result.IsSuccess)
            {
                DropboxContentInfo content = JsonConvert.DeserializeObject <DropboxContentInfo>(result.Response);

                if (content != null)
                {
                    if (createShareableURL)
                    {
                        DropboxShares shares = CreateShareableLink(content.Path, shortURL);

                        if (shares != null)
                        {
                            result.URL = shares.URL;
                        }
                    }
                    else
                    {
                        result.URL = GetPublicURL(content.Path);
                    }
                }
            }

            return(result);
        }
Example #4
0
        // https://www.dropbox.com/developers/core/docs#fileops-delete
        public DropboxContentInfo Delete(string path)
        {
            DropboxContentInfo contentInfo = null;

            if (!string.IsNullOrEmpty(path) && OAuth2Info.CheckOAuth(AuthInfo))
            {
                Dictionary <string, string> args = new Dictionary <string, string>();
                args.Add("root", Root);
                args.Add("path", path);

                string response = SendRequest(HttpMethod.POST, URLDelete, args, GetAuthHeaders());

                if (!string.IsNullOrEmpty(response))
                {
                    contentInfo = JsonConvert.DeserializeObject <DropboxContentInfo>(response);
                }
            }

            return(contentInfo);
        }
Example #5
0
        // https://www.dropbox.com/developers/core/docs#metadata
        public DropboxContentInfo GetMetadata(string path, bool list)
        {
            DropboxContentInfo contentInfo = null;

            if (OAuth2Info.CheckOAuth(AuthInfo))
            {
                string url = URLHelpers.CombineURL(URLMetaData, URLHelpers.URLPathEncode(path));

                Dictionary <string, string> args = new Dictionary <string, string>();
                args.Add("list", list ? "true" : "false");

                string response = SendRequest(HttpMethod.GET, url, args, GetAuthHeaders());

                if (!string.IsNullOrEmpty(response))
                {
                    contentInfo = JsonConvert.DeserializeObject <DropboxContentInfo>(response);
                }
            }

            return(contentInfo);
        }
Example #6
0
        // https://www.dropbox.com/developers/core/api#fileops-create-folder
        public DropboxContentInfo CreateFolder(string path)
        {
            DropboxContentInfo contentInfo = null;

            if (!string.IsNullOrEmpty(path) && OAuthInfo.CheckOAuth(AuthInfo))
            {
                Dictionary <string, string> args = new Dictionary <string, string>();
                args.Add("root", Root);
                args.Add("path", path);

                string query = OAuthManager.GenerateQuery(URLCreateFolder, args, HttpMethod.POST, AuthInfo);

                string response = SendRequest(HttpMethod.POST, query);

                if (!string.IsNullOrEmpty(response))
                {
                    contentInfo = JsonConvert.DeserializeObject <DropboxContentInfo>(response);
                }
            }

            return(contentInfo);
        }
Example #7
0
        // https://www.dropbox.com/developers/core/api#fileops-move
        public DropboxContentInfo Move(string from_path, string to_path)
        {
            DropboxContentInfo contentInfo = null;

            if (!string.IsNullOrEmpty(from_path) && !string.IsNullOrEmpty(to_path) && OAuthInfo.CheckOAuth(AuthInfo))
            {
                Dictionary <string, string> args = new Dictionary <string, string>();
                args.Add("root", Root);
                args.Add("from_path", from_path);
                args.Add("to_path", to_path);

                string query = OAuthManager.GenerateQuery(URLMove, args, HttpMethod.Post, AuthInfo);

                string response = SendPostRequest(query);

                if (!string.IsNullOrEmpty(response))
                {
                    contentInfo = JsonConvert.DeserializeObject <DropboxContentInfo>(response);
                }
            }

            return(contentInfo);
        }
Example #8
0
        // https://www.dropbox.com/developers/core/api#metadata
        public DropboxContentInfo GetMetadata(string path, bool list)
        {
            DropboxContentInfo contentInfo = null;

            if (OAuthInfo.CheckOAuth(AuthInfo))
            {
                string url = Helpers.CombineURL(URLMetaData, Helpers.URLPathEncode(path));

                Dictionary <string, string> args = new Dictionary <string, string>();
                args.Add("list", list ? "true" : "false");

                string query = OAuthManager.GenerateQuery(url, args, HttpMethod.Get, AuthInfo);

                string response = SendGetRequest(query);

                if (!string.IsNullOrEmpty(response))
                {
                    contentInfo = JsonConvert.DeserializeObject <DropboxContentInfo>(response);
                }
            }

            return(contentInfo);
        }
Example #9
0
        public bool IsExists(string path)
        {
            DropboxContentInfo contentInfo = GetMetadata(path, false);

            return(contentInfo != null && !contentInfo.Is_deleted);
        }