public static void Main(string[] args)
        {
            // Pleace fill the DropboxAppKey and DropboxAppSecret with your credentionals before you test the app.
            DropboxServiceProvider dropboxServiceProvider =
                new DropboxServiceProvider(DropboxAppKey, DropboxAppSecret, AccessLevel.AppFolder);

            var oauthAccessToken = AuthorizeAppOAuth(dropboxServiceProvider);

            IDropbox dropbox = dropboxServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret);

            DropboxProfile profile = dropbox.GetUserProfileAsync().Result;

            Console.WriteLine("Hi " + profile.DisplayName + "!");

            string newFolderName     = "Your_New_Images_Folder";
            Entry  createFolderEntry = dropbox.CreateFolderAsync(newFolderName).Result;

            var imageAsFileResource = new FileResource("../../Images/image1.jpg");
            var pathToUpload        = "/" + newFolderName + "/image1.jpg";

            Entry uploadFileEntry = dropbox.UploadFileAsync(imageAsFileResource, pathToUpload).Result;

            Console.WriteLine("Uploaded a file: {0}", uploadFileEntry.Path);

            DropboxLink sharedUrl = dropbox.GetShareableLinkAsync(uploadFileEntry.Path).Result;

            Process.Start(sharedUrl.Url);
        }
示例#2
0
        public string Upload(string file)
        {
            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;

            // Create new folder
            string newFolderName     = "New_Folder_" + DateTime.Now.Ticks;
            Entry  createFolderEntry = dropbox.CreateFolderAsync(newFolderName).Result;

            var    splitetFileDirectory = file.Split(new char[] { '/', '\\' });
            string fileName             = splitetFileDirectory[splitetFileDirectory.Length - 1];

            // Upload a file
            Entry uploadFileEntry = dropbox.UploadFileAsync(
                new FileResource(file),                 //("../../DropboxExample.cs"),
                "/" + newFolderName + fileName).Result; //"/DropboxExample.cs").Result;

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

            //Open the file location
            return(sharedUrl.Url.ToString());
        }
示例#3
0
        public static void Main()
        {
            DropboxServiceProvider dropboxServiceProvider =
                new DropboxServiceProvider(DropboxAppKey, DropboxAppSecret, AccessLevel.AppFolder);

            // Authenticate the application (if not authenticated) and load the OAuth token
            if (!File.Exists(OAuthTokenFileName))
            {
                AuthorizeAppOAuth(dropboxServiceProvider);
            }
            OAuthToken oauthAccessToken = LoadOAuthToken();

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

            // Create new folder
            string newFolderName     = "Test";
            Entry  createFolderEntry = dropbox.CreateFolderAsync(newFolderName).Result;

            Console.WriteLine("Created folder: {0}", createFolderEntry.Path);

            // Upload a file
            Entry uploadFileEntry = dropbox.UploadFileAsync(
                new FileResource("../../cat.jpg"),
                "/" + newFolderName + "/cat.jpg").Result;

            Console.WriteLine("Uploaded a file: {0}", uploadFileEntry.Path);

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

            Process.Start(sharedUrl.Url);
        }
示例#4
0
        private static async Task <Entry> CreateFolderAsync(IDropbox dropbox, string newFolderName)
        {
            var createFolderEntry = await dropbox.CreateFolderAsync(newFolderName);

            Console.WriteLine("Created folder: {0}", createFolderEntry.Path);
            return(createFolderEntry);
        }
示例#5
0
        private static Entry CreateDropboxFolder(IDropbox dropbox, string folderName)
        {
            Entry folderEntry = dropbox
                .CreateFolderAsync(folderName)
                .Result;
            Console.WriteLine("Created folder: {0}", folderEntry.Path);

            return folderEntry;
        }
    private static void Main()
    {
        DropboxServiceProvider dropboxServiceProvider =
            new DropboxServiceProvider(AppKey, AppSecret, AccessLevel.AppFolder);

        if (!File.Exists(OAuthTokenFileName))
        {
            AuthorizeAppViaOAuth(dropboxServiceProvider);
        }

        OAuthToken oAuthAccessToken = LoadOAuthToken();

        IDropbox dropbox = dropboxServiceProvider.GetApi(oAuthAccessToken.Value, oAuthAccessToken.Secret);

        Entry  folderEntry = new Entry();
        string folderName  = string.Empty;

        while (true)
        {
            try
            {
                Console.WriteLine("Folder name:");
                folderName  = Console.ReadLine();
                folderEntry = dropbox.CreateFolderAsync(folderName).Result;
                Console.WriteLine("Folder '{0}' created.", folderEntry.Path);
                break;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.InnerException.Message);
            }
        }

        Console.WriteLine("Number of files to upload:");

        int filesCount = int.Parse(Console.ReadLine());

        for (int i = 0; i < filesCount; i++)
        {
            Console.WriteLine("File path:");
            string filePath        = Console.ReadLine().Trim();
            Entry  uploadFileEntry = dropbox.UploadFileAsync(
                new FileResource(filePath), "/" + folderName + "/" + Path.GetFileName(filePath)).Result;
            Console.WriteLine("File '{0}' uploaded.", uploadFileEntry.Path);
        }

        DropboxLink sharedUrl = dropbox.GetShareableLinkAsync(folderEntry.Path).Result;

        Console.WriteLine(sharedUrl.Url);
        Process.Start(sharedUrl.Url);
    }
示例#7
0
        static void Main()
        {
            DropboxServiceProvider dropboxServiceProvider =
                new DropboxServiceProvider(DropboxAppKey, DropboxAppSecret, AccessLevel.AppFolder);

            // Authenticate the application (if not authenticated) and load the OAuth token
            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 = "BatmanAlbum";
            DeltaPage deltaPage     = dropbox.DeltaAsync(null).Result;
            var       isFolderExist = deltaPage.Entries.Any(x => x.Path == ("/" + newFolderName).ToLower());

            if (!isFolderExist)
            {
                Entry createFolderEntry = dropbox.CreateFolderAsync(newFolderName).Result;
                Console.WriteLine("Created folder: {0}", createFolderEntry.Path);
            }

            var           folderPath     = @"../../Pics";
            DirectoryInfo picturesFolder = new DirectoryInfo(folderPath);

            foreach (var fileName in picturesFolder.GetFiles("*.jpg"))
            {
                // Upload a file
                Entry uploadFileEntry = dropbox.UploadFileAsync(
                    new FileResource(fileName.FullName),
                    "/" + newFolderName + "/" + fileName.Name).Result;
                Console.WriteLine("Uploaded a file: {0}", uploadFileEntry.Path);

                // Share a file
                DropboxLink sharedUrl = dropbox.GetShareableLinkAsync(uploadFileEntry.Path).Result;
                Process.Start(sharedUrl.Url);
            }
        }
示例#8
0
        static void Main()
        {
            DropboxServiceProvider dropboxServiceProvider =
                new DropboxServiceProvider(DropboxAppKey, DropboxAppSecret, AccessLevel.AppFolder);

            // Authenticate the application (if not authenticated) and load the OAuth token
            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     = "PhotoAlbum_" + DateTime.Now.Ticks;
            Entry  createFolderEntry = dropbox.CreateFolderAsync(newFolderName).Result;

            Console.WriteLine("Created folder: {0}", createFolderEntry.Path);

            // Upload a file
            Entry uploadFileEntry = dropbox.UploadFileAsync(
                new FileResource("../../girl1.jpg"),
                "/" + newFolderName + "/girl1.jpg").Result;

            Console.WriteLine("Uploaded a file: {0}", uploadFileEntry.Path);

            Entry uploadFileEntry2 = dropbox.UploadFileAsync(
                new FileResource("../../girl2.jpg"),
                "/" + newFolderName + "/girl12.jpg").Result;

            Console.WriteLine("Uploaded a file: {0}", uploadFileEntry.Path);

            // Share a file
            DropboxLink sharedUrl = dropbox.GetShareableLinkAsync(createFolderEntry.Path).Result;

            Process.Start(sharedUrl.Url);
        }
 private static async Task<Entry> CreateFolderAsync(IDropbox dropbox, string newFolderName)
 {
     var createFolderEntry = await dropbox.CreateFolderAsync(newFolderName);
     Console.WriteLine("Created folder: {0}", createFolderEntry.Path);
     return createFolderEntry;
 }