JoshBab
The solution to this is simple and I would highlight the procedure thus:
1.)Create an app from Dropbox App Console. Choose App Folder (this is a preferable option) or Full Dropbox for Access Type; enter a name for your app (e.g. myapp). Click "Create App" button.
Another page is displayed, click on "Generate" button under Generated Access Token.
For the rest of this write-up, the generated code will be called "token".
2.)In your Program.cs (assuming you're using Console App), ensure the following namespaces are referenced
using System;
using System.Threading.Tasks;
using Dropbox.Api;
using System.IO;
Then, modify your your code to
class Program
{
static void Main(string[] args)
{
var task = Task.Run(Upload);
task.Wait();
}
static async Task Upload()
{
var dbx = new DropboxClient("token");
var filePath = @"c:\myFile.txt"; //for example
if(File.Exists(filePath))
{
var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
byte[] content;
using(var reader = new BinaryReader(fileStream))
{
content = reader.ReadBytes((int)fileStream.Length);
}
using(var mem = new MemoryStream(content))
{
await dbx.Files.UploadAsync("/myFile.txt", WriteMode.Overwrite.Instance, body:
mem);
}
}
}
}
3.) Add Newtonsoft.Json package using NuGet Package Manager and you are done.
There is a better approach to uploading bigger-sized files. But I hope this suites your scenario.