Dropbox API 使用具有进度跟踪的Dropbox .NET库下载文件
示例
这将使用Dropbox.NETSDK从远程的DropboxAPI将文件下载path到本地文件“Test”,同时跟踪进度:
var response = await client.Files.DownloadAsync(path); ulong fileSize = response.Response.Size; const int bufferSize = 1024 * 1024; var buffer = new byte[bufferSize]; using (var stream = await response.GetContentAsStreamAsync()) { using (var file = new FileStream("Test", FileMode.OpenOrCreate)) { var length = stream.Read(buffer, 0, bufferSize); while (length > 0) { file.Write(buffer, 0, length); var percentage = 100 * (ulong)file.Length / fileSize; //用百分比更新进度栏。 //progressBar.Value=(int)百分比 Console.WriteLine(percentage); length = stream.Read(buffer, 0, bufferSize); } } }