cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Musicians, convert your MuseScore files to PDF to play music on the go! Learn more here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

System.Configuration.ConfigurationErrorsException was caught during uploading file to dropbox using

System.Configuration.ConfigurationErrorsException was caught during uploading file to dropbox using

shashi93
New member | Level 2

This Code is working fine with console application, but I am getting error with windows service saying Configuration system failed to initialize(System.Configuration.ConfigurationErrorsException was caught)

 

 

private static async Task Backup()
    {        using (var dbx = new DropboxClient("<REDACTED>")) 
        {
            string folder = "DropboxUpload";
            string file = "setup.exe";
            string content = @"D:\Share\setup.exe";            log.Info("Chunk upload file...");
            // Chunk size is 100 mb.
            const int chunkSize = 2 * 1024 * 1024;            using (var stream = new FileStream(content, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                int numChunks = (int)Math.Ceiling((double)stream.Length / chunkSize);
                byte[] buffer = new byte[chunkSize];
                string sessionId = null;
                for (var idx = 0; idx < numChunks; idx++)
                {                    log.Info("Start uploading chunk {0}" +idx);
                    var byteRead = stream.Read(buffer, 0, chunkSize);                    using (MemoryStream memStream = new MemoryStream(buffer, 0, byteRead))
                    {
                        if (stream.Length <= chunkSize)
                        {  
                          // here i am getting exception                         await dbx.Files.UploadAsync(new CommitInfo("/" +folder + "/" + file), body: memStream);
                        }
                        else if (idx == 0)
                        {
                            var result = await dbx.Files.UploadSessionStartAsync(body: memStream);                            sessionId = result.SessionId;
                        }
                        else
                        {
                            UploadSessionCursor cursor = new UploadSessionCursor(sessionId, (ulong)(chunkSize * idx));
                            if (idx == numChunks - 1)
                            {                                await dbx.Files.UploadSessionFinishAsync(cursor, new CommitInfo("/" + folder + "/" + file), memStream);                                log.Info("BackUp Completed...!!!");
                            }
                            else
                            {                                await dbx.Files.UploadSessionAppendV2Async(cursor, body: memStream);
                            }
                        }
                    }
                }
            }
        }
    }
1 Reply 1

Greg-DB
Dropbox Staff
[Cross-linking for reference: https://stackoverflow.com/questions/44173750/system-configuration-configurationerrorsexception-was-c... ]

I redacted it for you, but for the sake of security, you should disable that access token that you posted. You can do so by revoking access to the app entirely, if the access token is for your account, here:

https://www.dropbox.com/account/security

Or, you can disable just this access token using the API:

https://www.dropbox.com/developers/documentation/http/documentation#auth-token-revoke
Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?