Upload File From Local Disk To A Specific Box Folder in C#
Upload File From Local Disk To A Specific Box Folder in C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Box.V2;
using Box.V2.Auth;
using Box.V2.Config;
using Box.V2.Exceptions;
using Box.V2.Models;
using Nito.AsyncEx;
using System.IO;
namespace MoveFileFromDiskToBox
{
//Make sure you install the NuGet package 'Box Windows SDK V2'
class Program
{
const string CLIENT_ID = "YOUR_CLIENT_ID";
const string CLIENT_SECRET = "YOUR_CLIENT_SECRET";
const string DEV_ACCESS_TOKEN = "YOUR_DEV_ACCESS_TOKEN"; //log into
developers.box.com and get this for your registered app; it will last for 60
minutes
const string REFRESH_TOKEN =
"THIS_IS_NOT_NECESSARY_FOR_A_DEV_TOKEN_BUT_MUST_BE_HERE";
//set these to point to whatever file you want to upload; make sure it
exists!
const string PATH_TO_FILE = "C:\\";
const string FILENAME = "example.pdf";
Console.WriteLine();
Console.Write("Press return to exit...");
Console.ReadLine();
}
// Create request object with name and parent folder the file
should be uploaded to
BoxFileRequest request = new BoxFileRequest()
{
Name = FILENAME,
Parent = new BoxRequestEntity() { Id = boxFolderId }
};
BoxFile f = await client.FilesManager.UploadAsync(request, fs);
}
}
return currFolderId;
}
}
}
==================
Yes, Developer token expires in 60 mins. How to retrieve developer token on every
request if it expires? can we use access token?