Пример #1
0
        public string UploadFileToDropBox(string filePath, string fileName)
        {
            DropboxServiceProvider dropboxServiceProvider =
                new DropboxServiceProvider(DropboxAppKey, DropboxAppSecret, AccessLevel.AppFolder);

            // Authenticate the application (if not authenticated) and load the OAuth token
            // TODO - throw exception if auth file is not found
            //if (!File.Exists(OAuthTokenFileName))
            //{
            //    AuthorizeAppOAuth(dropboxServiceProvider);
            //}
            OAuthToken oauthAccessToken = LoadOAuthToken();

            // Login in Dropbox
            IDropbox dropbox = dropboxServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret);

            // Display user name (from his profile)
            //DropboxProfile profile = dropbox.GetUserProfileAsync().Result;
            //Console.WriteLine("Hi " + profile.DisplayName + "!");

            // Create new folder
            string newFolderName = DateTime.Now.Ticks.ToString();
            //Entry createFolderEntry = dropbox.CreateFolderAsync(newFolderName).Result;
            Entry createFolderEntry = dropbox.CreateFolder(newFolderName);
            // Upload a file
            Entry uploadFileEntry = dropbox.UploadFile(
                new FileResource(filePath),
                "/" + newFolderName + "/" + fileName);

            // Share a file
            //DropboxLink sharedUrl = dropbox.GetShareableLinkAsync(uploadFileEntry.Path).Result;
            string sharedUrl = dropbox.GetMediaLink(uploadFileEntry.Path).Url.ToString();

            // var ret = sharedUrl.Url.ToString();
            return(sharedUrl);
        }
Пример #2
0
 public static void CreateFolder(Album album)
 {
     Entry createFolderEntry = dropbox.CreateFolder(album.Path + "/" + album.AlbumName);
 }