Download File to Byte Array

Feb 10, 2013 at 11:37 AM
I've been using the .downloadFile() method to successfully save Dropbox files to the local file system.

I'd now like to download directly to a byte array so it can then be moved to a cloud storage service.

Any code samples would be much appreciated!
Feb 11, 2013 at 8:35 AM
The following works well for me.
    public byte[] DownloadContent()
    {
        ICloudFileSystemEntry file = CloudStore.GetFile(filePath, rootFolder);

        ICloudFileDataTransfer tf = file.GetDataTransferAccessor();
        byte[] array = new byte[file.Length];
        Stream sourceStream = new MemoryStream(array);
        tf.Transfer(sourceStream, nTransferDirection.nDownload, null, null);
        return array;
    }
Feb 11, 2013 at 9:52 AM
In case this was your next question
    public void UploadNewDocument(ICloudDirectoryEntry folder, string fileName, byte[] content)
    {
        Stream sourceStream = new MemoryStream(content);
        ICloudFileSystemEntry file = CloudStore.CreateFile(folder, fileName);
        ICloudFileDataTransfer tf = file.GetDataTransferAccessor();
        tf.Transfer(sourceStream, nTransferDirection.nUpload, null, null);
    }
Feb 11, 2013 at 5:01 PM
Excellent, that's very helpful...many thanks!