Your workflow is unique 👨‍💻 -  tell us how you use Dropbox here.

Forum Discussion

shashi93's avatar
shashi93
New member | Level 2
8 years ago

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

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

About Dropbox API Support and Feedback

Node avatar for Dropbox API Support and Feedback
Get help with the Dropbox API from fellow developers and experts.

The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!