I have a function to upload serialized data (myData) to OneDrive.
private async void Upload_Click( object sender, System.EventArgs e )
{
if ( LiveHelper.Session == null )
{
var liveStatus = await LiveHelper.InitAuth( App.ClientId );
await LiveHelper.LoadLiveProfile();
}
const string myDataFoldr = "myData";
string folderId = await LiveHelper.GetFolderID( myDataFoldr );
folderId = ( string.IsNullOrEmpty( folderId )
? await LiveHelper.CreateFolder( LiveHelper.RootFolder, myDataFoldr )
: folderId );
string fileId = await LiveHelper.BackgroundUploadFile( folderId, _app.myData, App.SkyDriveFileName );
}
public static async Task<string> BackgroundUploadFile<T>( string skydriveFolderId,
T objectToSerialize,
string fileNameInSkyDrive,
BackgroundTransferPreferences backgroundTransferPreferences = BackgroundTransferPreferences.AllowCellularAndBattery )
{
string fileId = string.Empty;
try
{
var storageFolder = await GetSharedTransfersFolder();
StorageFile isolatedstorageFile = await storageFolder.CreateFileAsync( fileNameInSkyDrive, CreationCollisionOption.ReplaceExisting );
using ( var writer = new StreamWriter( await isolatedstorageFile.OpenStreamForWriteAsync() ) )
{
// convert to string
var _String = Serialize( objectToSerialize );
await writer.WriteAsync( _String );
}
Client.BackgroundTransferPreferences = backgroundTransferPreferences;
LiveOperationResult liveOpResult = await Client.BackgroundUploadAsync( skydriveFolderId, new Uri( @"\shared/transfers\" + fileNameInSkyDrive, UriKind.Relative ), OverwriteOption.Overwrite );
fileId = (string)liveOpResult.Result[ "id" ];
Debug.WriteLine( "BackgroundUploadFile: " + fileNameInSkyDrive );
}
catch ( Exception e )
{
Debug.WriteLine( "\nError - BackgroundUploadFile: " + e.Message );
}
return fileId;
}
When testing this function using the emulator/debugger combination the data was uploaded properly.
I also tested the code on a phone, and ran it under the device/debugger and device/release combination. Under both combinations the data was uploaded properly.
However when publishing the application and then trying to upload the data, the data was not being uploaded on the same phone of step #2. (On another phone, with a different Live ID, the upload works fine).
The same phone from step #3 was able to download the data from the OneDrive (the data was there from steps #2 & #3).
Can anybody explain why the upload fails in my case?