The SharpBox API has a bug with Box.Net storage provider see
A Cloud Storage Programming Interface - Store everything - sharpbox - View Issue #16934: BoxDotNet GetRoot(); always returning NULL.
--- sample console application showing how to list , upload and download dropbox and box.net files.
static void Main(string[] args)
{
CloudStorage dropBoxStorage = new CloudStorage();
CloudStorage boxNetStorage = new CloudStorage();
//credentials access
GenericNetworkCredentials cred = new GenericNetworkCredentials();
cred.UserName =
somebody@somemail.com;
cred.Password =
"somePassword";
//access token
ICloudStorageAccessToken accessToken = null;
using (FileStream fs = File.Open("dropbox", FileMode.Open, FileAccess.Read, FileShare.None))
{
accessToken = dropBoxStorage.DeserializeSecurityToken(fs);
}
var dropBoxConfig = CloudStorage.GetCloudConfigurationEasy(nSupportedCloudConfigurations.DropBox);
var boxNetConfig = CloudStorage.GetCloudConfigurationEasy(nSupportedCloudConfigurations.BoxNet);
var boxNetstorageToken = boxNetStorage.Open(boxNetConfig, cred);
var dropBoxstorageToken = dropBoxStorage.Open(dropBoxConfig, accessToken);
var boxNetRoot = boxNetStorage.GetRoot();
var dropBoxRoot = dropBoxStorage.GetRoot();
foreach (var fof in boxNetRoot)
{
Boolean bIsDir = fof is ICloudDirectoryEntry;
Console.WriteLine("{0}:{1}", bIsDir ? "DIR" : "FIL", fof.Name);
}
foreach (var fof in dropBoxRoot)
{
Boolean bIsDir = fof is ICloudDirectoryEntry;
Console.WriteLine("{0}:{1}", bIsDir ? "DIR" : "FIL", fof.Name);
}
string tmpFile = Environment.ExpandEnvironmentVariables("%temp%");
//Console.WriteLine("Downloading..");
//dropBoxStorage.DownloadFile(dropBoxRoot, "big_file",tmpFile, UploadDownloadProgress);
Console.WriteLine("Uploading..");
boxNetStorage.UploadFile(tmpFile+
"\\big_file", boxNetRoot, UploadDownloadProgress);
Console.WriteLine("Completed");
boxNetStorage.Close();
dropBoxStorage.Close();
}
static void UploadDownloadProgress(Object sender, FileDataTransferEventArgs e)
{
Console.Write("x");
e.Cancel =
false;
}
}
No comments:
Post a Comment