<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic .Net/C# - getting list of files and then downloading to local drive in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Net-C-getting-list-of-files-and-then-downloading-to-local-drive/m-p/393008#M21666</link>
    <description>&lt;P&gt;I'm back again!&lt;/P&gt;
&lt;PRE&gt;public class Program
    {
        public Logger logger;
        public string localFilePath = @"C:\Users\hbuuutaag\Documents\Code Tests\Test";

            
        public static void Main(string[] args)
        {
            Program program = new Program();
            var task = Task.Run((Func&amp;lt;Task&amp;gt;)program.Run);
            task.Wait();
            
        }

        public async Task Run()
        {
                      
            using (var dbx = new DropboxClient("API TOKEN"))
            {
                logger = NLog.LogManager.GetLogger("logger");

                var full = await dbx.Users.GetCurrentAccountAsync();
                logger.Info("{0} - {1}", full.Name.DisplayName, full.Email);

                var listOfFolders = await dbx.Files.ListFolderAsync(string.Empty, true);

                FolderMetadata dropboxFolderInfo = new FolderMetadata();
                FileMetadata dropboxFileInfo = new FileMetadata();


                foreach (var item in listOfFolders.Entries)
                {
                    try
                    {
                        if (item.IsFile)
                        {
                            dropboxFileInfo = (FileMetadata)item;
                            
                            logger.Info("Processing " + dropboxFileInfo.PathLower.ToString());
                            
                            using (var response = await dbx.Files.DownloadAsync(dropboxFileInfo.PathLower.ToString()))
                            {
                                using (FileStream fileStream = File.Create(localFilePath))
                                {
                                    (await response.GetContentAsStreamAsync()).CopyTo(fileStream);
                                    
                                    logger.Info("Downloaded " + dropboxFileInfo.PathLower.ToString() + " successfully");
                                    
                                }

                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.ToString() + "\t" + dropboxFileInfo);
                    }
                }&lt;/PRE&gt;
&lt;P&gt;I'm iterating through the list of folders successfully, but when I try to pass the file name in to the download handler it's downloading one document with Wingdings galore! Probably missing something super basic...&lt;/P&gt;
&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
    <pubDate>Tue, 28 Jan 2020 16:46:08 GMT</pubDate>
    <dc:creator>hbuuutag</dc:creator>
    <dc:date>2020-01-28T16:46:08Z</dc:date>
    <item>
      <title>.Net/C# - getting list of files and then downloading to local drive</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Net-C-getting-list-of-files-and-then-downloading-to-local-drive/m-p/393008#M21666</link>
      <description>&lt;P&gt;I'm back again!&lt;/P&gt;
&lt;PRE&gt;public class Program
    {
        public Logger logger;
        public string localFilePath = @"C:\Users\hbuuutaag\Documents\Code Tests\Test";

            
        public static void Main(string[] args)
        {
            Program program = new Program();
            var task = Task.Run((Func&amp;lt;Task&amp;gt;)program.Run);
            task.Wait();
            
        }

        public async Task Run()
        {
                      
            using (var dbx = new DropboxClient("API TOKEN"))
            {
                logger = NLog.LogManager.GetLogger("logger");

                var full = await dbx.Users.GetCurrentAccountAsync();
                logger.Info("{0} - {1}", full.Name.DisplayName, full.Email);

                var listOfFolders = await dbx.Files.ListFolderAsync(string.Empty, true);

                FolderMetadata dropboxFolderInfo = new FolderMetadata();
                FileMetadata dropboxFileInfo = new FileMetadata();


                foreach (var item in listOfFolders.Entries)
                {
                    try
                    {
                        if (item.IsFile)
                        {
                            dropboxFileInfo = (FileMetadata)item;
                            
                            logger.Info("Processing " + dropboxFileInfo.PathLower.ToString());
                            
                            using (var response = await dbx.Files.DownloadAsync(dropboxFileInfo.PathLower.ToString()))
                            {
                                using (FileStream fileStream = File.Create(localFilePath))
                                {
                                    (await response.GetContentAsStreamAsync()).CopyTo(fileStream);
                                    
                                    logger.Info("Downloaded " + dropboxFileInfo.PathLower.ToString() + " successfully");
                                    
                                }

                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.ToString() + "\t" + dropboxFileInfo);
                    }
                }&lt;/PRE&gt;
&lt;P&gt;I'm iterating through the list of folders successfully, but when I try to pass the file name in to the download handler it's downloading one document with Wingdings galore! Probably missing something super basic...&lt;/P&gt;
&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jan 2020 16:46:08 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Net-C-getting-list-of-files-and-then-downloading-to-local-drive/m-p/393008#M21666</guid>
      <dc:creator>hbuuutag</dc:creator>
      <dc:date>2020-01-28T16:46:08Z</dc:date>
    </item>
    <item>
      <title>Re: .Net/C# - getting list of files and then downloading to local drive</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Net-C-getting-list-of-files-and-then-downloading-to-local-drive/m-p/393044#M21668</link>
      <description>&lt;P&gt;I see you've already found the methods for downloading a file, and it sounds like you are getting the file data successfully. If the download call failed it would raise an exception.&lt;/P&gt;
&lt;P&gt;It sounds like you're having an issue viewing the file though, perhaps due to reading it with an incorrect encoding. How are you viewing/accessing the downloaded file? Depending on the file type/encoding you may need to open it with a different application and/or encoding setting. (I can't offer support for configuring third party applications though of course.)&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jan 2020 17:45:54 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Net-C-getting-list-of-files-and-then-downloading-to-local-drive/m-p/393044#M21668</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2020-01-28T17:45:54Z</dc:date>
    </item>
    <item>
      <title>Re: .Net/C# - getting list of files and then downloading to local drive</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Net-C-getting-list-of-files-and-then-downloading-to-local-drive/m-p/393206#M21673</link>
      <description>&lt;P&gt;Wasn't sure what I was doing incorrectly but managed to get it sorted - the issue was using the .PathLower rather than .Name attributes.&lt;/P&gt;&lt;P&gt;Thanks again for the quick response Greg! &lt;img class="lia-deferred-image lia-image-emoji" src="https://www.dropboxforum.com/html/@FBF7D2AB59A0D6E861EBF6A36F93B7E2/emoticons/1f642.png" alt=":slightly_smiling_face:" title=":slightly_smiling_face:" /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jan 2020 10:45:29 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Net-C-getting-list-of-files-and-then-downloading-to-local-drive/m-p/393206#M21673</guid>
      <dc:creator>hbuuutag</dc:creator>
      <dc:date>2020-01-29T10:45:29Z</dc:date>
    </item>
  </channel>
</rss>

