// 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) { AllowReportProgress = false; 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; }
// 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); }
// 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); }
// https://www.dropbox.com/developers/core/docs#fileops-copy public DropboxContentInfo Copy(string from_path, string to_path) { DropboxContentInfo contentInfo = null; if (!string.IsNullOrEmpty(from_path) && !string.IsNullOrEmpty(to_path) && OAuth2Info.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 response = SendRequest(HttpMethod.POST, URLCopy, args, GetAuthHeaders()); if (!string.IsNullOrEmpty(response)) { contentInfo = JsonConvert.DeserializeObject<DropboxContentInfo>(response); } } return contentInfo; }
public bool IsExists(string path) { DropboxContentInfo contentInfo = GetMetadata(path, false); return(contentInfo != null && !contentInfo.Is_deleted); }