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);
}
}
}
}
}
}
}