IsolatedStorageFile copied to Dropbox

SJamG

New member
Nov 3, 2011
48
0
0
Hi,

I am building an app which allows you to put in a url of a file and it downloads the file into IsolatedStorageFile. However, hopefully i have it in there, I would like to copy the file from there into a folder on my dropbox account.

I would really appreciate it if someone could show me how to copy the file or even just store the filename in a string (so i can at least see it is definitely storing the file)

Here is my code :



private void downloadButton_Click(object sender, RoutedEventArgs e)
{
webClient = new WebClient();
webClient.OpenReadCompleted += (s1, e1) =>
{
if (e1.Error == null)
{
try
{
string fileName = txtUrl.Text.Substring(txtUrl.Text.LastIndexOf("/") + 1).Trim();
bool isSpaceAvailable = IsSpaceIsAvailable(e1.Result.Length);

if (isSpaceAvailable)
{
// Save mp3 to Isolated Storage
using (var isfs = new IsolatedStorageFileStream(fileName,
FileMode.CreateNew,
IsolatedStorageFile.GetUserStoreForApplication()))
{
long fileLen = e1.Result.Length;
byte[] b = new byte[fileLen];
e1.Result.Read(b, 0, b.Length);
isfs.Write(b, 0, b.Length);
isfs.Flush();
}

}
else
{
MessageBox.Show("Not enough to save space available to download the file");
}

}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
else
{
MessageBox.Show(e1.Error.Message);
}
};



}

private bool IsSpaceIsAvailable(long spaceReq)
{
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
long spaceAvail = store.AvailableFreeSpace;
if (spaceReq > spaceAvail)
{
return false;
}
return true;
}
}




This is my first C# WP7 app and I have had very little experience with this - so I would really appreciate the help!



Thanks

SJG
 
There's a tool bundled with the Windows Phone (7.1) SDK called the Isolated Storage Explorer that is very useful to transfer the contents of an app's isolated storage to your PC and also send files/folders from your PC to the isolated storage for your app. You can read more about it at 31 Days of Mango | Day #16: Isolated Storage Explorer ? Blankenblog.

It also looks like you're missing the call to webClient.OpenReadAsync to start the file download. OpenReadAsync should be called after you register for the webClient.OpenReadCompleted event.
 

Members online

No members online now.

Forum statistics

Threads
333,680
Messages
2,256,628
Members
428,709
Latest member
uii