This project is read-only.
1
Vote

unable to sync to Box.net (box.com)

description

hello,

I am attempting to connect to my box account using sharpbox, however I keep getting a file not found error.
the code I am using is below. any ideas? on my account I have the default folder and a backup folder.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using AppLimit.CloudComputing.SharpBox;
using AppLimit.CloudComputing.SharpBox.StorageProvider;
using AppLimit.CloudComputing.SharpBox.StorageProvider.WebDav;

class Program
{
    static void Main(string[] args)
    {
        CloudStorage BoxStorage = new CloudStorage();
        // Box.Net ad hoc configuration instance
        var boxnetConfig = CloudStorage.GetCloudConfigurationEasy(nSupportedCloudConfigurations.BoxNet);

        // building credentials for the service 
        var webDavCredentials = new GenericNetworkCredentials();

        // set the information you got from the enduser 
        webDavCredentials.UserName = "shhhdonttell"; 
        webDavCredentials.Password = "ahahahnotthemagicword";

        // open the connection 
        var storageToken = BoxStorage.Open(boxnetConfig, webDavCredentials);
        var publicFolder = BoxStorage.GetFolder("/Default");
        String srcFile = Environment.ExpandEnvironmentVariables("C:\\EyeCandyLog.txt"); 
        BoxStorage.UploadFile(srcFile, publicFolder);

        //// get a specific directory in the cloud storage, e.g. /Public 
        //var publicFolder = BoxStorage.GetFolder("/");

        //foreach (var fof in publicFolder)
        //{
        //    // check if we have a directory 
        //    Boolean bIsDirectory = fof is ICloudDirectoryEntry;

        //    // output the info 
        //    Console.WriteLine("{0}: {1}", bIsDirectory ? "DIR" : "FIL", fof.Name);
        //}

        // close the connection 
        BoxStorage.Close();
    }
}

comments

vijaykumarkagne wrote Dec 19, 2014 at 6:24 AM

I am attempting to connect to my box account using sharpbox, I am able to Connect my dropBox but is there any way to get all list of specific extension files and if choose one of them it should download,I am using following code
 DropBoxConfiguration config = AppLimit.CloudComputing.SharpBox.StorageProvider.DropBox.DropBoxConfiguration.GetStandardConfiguration();
                config.AuthorizationCallBack = new Uri("http://localhost/HTMLPage1.htm");
                // 1. get the request token from dropbox
                DropBoxRequestToken requestToken = DropBoxStorageProviderTools.GetDropBoxRequestToken(config, ConsumerKey, ComsumerSecret);

                // 2. build the authorization url based on request token                        
                String url = DropBoxStorageProviderTools.GetDropBoxAuthorizationUrl(config, requestToken);
               process.start(url);

  ICloudStorageAccessToken accessToken = null;
            // 4. Exchange the request token into access token
            label:
                try
                {
                    
                    accessToken = DropBoxStorageProviderTools.ExchangeDropBoxRequestTokenIntoAccessToken(config, ConsumerKey, ComsumerSecret, requestToken);
                }
                catch (Exception ex)
                {
                    Thread.Sleep(2000);
                    goto label;
                }

                // 5. Opent the storage with the generated access token            
                CloudStorage storageNew = new CloudStorage();

                CloudStorage storageNew1 = new CloudStorage();
                storageNew.Open(config, accessToken);
                // store the token in a stream
                Stream tokenStream = storageNew.SerializeSecurityToken(accessToken);

                //Just store the token stream as BLOB or Base64 text into your DB. To restore the token your can use the following code

                // read the token
                ICloudStorageAccessToken token2 = storageNew1.DeserializeSecurityToken(tokenStream);
                
                // use the token
                storageNew1.Open(config, token2);

                // 6. Try to do something
                ICloudDirectoryEntry r = storageNew1.GetRoot();
                ICloudFileSystemEntry fileEntry = storageNew1.GetRoot();
                List<string> FolderName = new List<string>();
                List<ICloudFileSystemEntry> FileName = new List<ICloudFileSystemEntry>();
                //int i = 0;
                foreach (var item in r)
                {
                    if (item.Length == 0)
                    {
                        FolderName.Add(item.Name);

                    }
                    else if (item.Length > 0)
                    {
                        FileName.Add(item);

                    }
                }
                foreach (var item in FileName)
                {
                    //storageNew1.DownloadFile(item.Parent, item.Name, @"D:\Excels");
                }