I am trying to upload a text file, myFile.txt, to SkyDrive. Below is the code:
private async void btnUpload_Click( object sender, System.Windows.RoutedEventArgs e )
{
Client = new LiveConnectClient( _session );
string filename = "myFile.txt";
var isolatedstorageFile= await ApplicationData.Current.LocalFolder.CreateFileAsync( filename, CreationCollisionOption.ReplaceExisting );
using ( StreamWriter writer = new StreamWriter( await isolatedstorageFile.OpenStreamForWriteAsync() ) )
{
// convert to string
var _String = Serialize( "this is a test file" );
await writer.WriteAsync( _String );
}
await Client.BackgroundUploadAsync( FolderID, new Uri( isolatedstorageFile.Path ), OverwriteOption.Overwrite );
}
FolderID is global and has the value of: "folder.17ff6230f5f26b89.17FF6230F5F26B89!1533"
The problem is in defining the second parameter of the BackgroundUploadAsync. How do I solve it, i.e. specify the URI of where "myFile.txt" IsolatedStorage file is?
Thanks,
You are passing 3 arguments in BackgroundUploadAsync
where first one is FolderId, and second is path of the file, which is wrong check the documentation first, second argument takes the file name only not the Path of file and the third one is the stream of file.
Also You can use UploadAsync
instead BackgroundUploadAsync
.
IsolatedStorageFileStream isfs = isf.OpenFile(FileName, FileMode.Open, FileAccess.Read);
var res = await client.UploadAsync(folderId, FileName, isfs, OverwriteOption.Overwrite);