Downloading Multiple Files from SkyDrive with Live 5.3 - windows-phone-8

I'm trying to download one or more files from SkyDrive using the Windows Phone emulator. I'm pretty new at the Live SDK and I'm lost following these pages:
multiple file download using SkyDrive API
https://msdn.microsoft.com/en-us/library/live/hh826531.aspx#downloading_files
They both use methods and classes not provided in Live SDK 5.3 (more specifically, client.DownloadCompleted and LiveDownloadCompletedEventArgs).

You must be using Windows Phone 8.0 SDK. DownloadCompleted and LiveDownloadCompletedEventArgs are part of the Microsoft.Live namespace on WP7.1.
In Windows Phone 8.0 DownloadAsync() is used with the await keyword. You can use it with or without progress notification.
Sample:
var result = await client.DownloadAsync(path); // path will be file id followed by '/content'
var stream = result.Stream;

Related

WinRT write to home group

Is it possible to create new folder in main Windows Phone folder? I am trying to access home group as follows:
var picturesLibrary = KnownFolders.HomeGroup;
var savedPicturesFolder = await picturesLibrary.CreateFolderAsync("folderName", CreationCollisionOption.OpenIfExists);
but it ends up having error. If i specify subfolder like Pictures it works correctly.
From the msdn docs
If your app is a Windows Phone Store app, reading the value of this property raises an exception of type System.Exception.
https://msdn.microsoft.com/en-us/windows.storage.knownfolders.homegroup?f=255&MSPPError=-2147217396
May be it does not supported in windows phone.
requirment
To access the HomeGroup folder, in the app manifest, specify at least
one of the following capabilities: Pictures Library, Music Library, or
Videos Library. Learn more about these capabilities in
Access to user resources using the Windows Runtime.

Best approach to monitor download progress with OneDrive API on WP8.1?

I have a WP8.1 app using the new OneDrive API. I use the C# SDK provided, I get therefore something like this:
var dlStream = await Connection.DownloadStreamForItemAsync(mNode.ItemReference(),
StreamDownloadOptions.Default);
file = await folder.CreateFileAsync(fileName,
CreationCollisionOption.ReplaceExisting).AsTask();
fileStream = (await file.OpenAsync(FileAccessMode.ReadWrite)).AsStream();
var v=dlStream.CopyToAsync(tn.FileStream);
I have not tried it yet, but it seems to be the right way to do it. My concern now is "how to monitor the transfer progress and status?"
Knowing that the DownloadStreamForItemAsync method does something like this:
response = await GetHttpResponseAsync(request);
var responseStream = await response.GetResponseStreamAsync();
I have thought about using a timer, and each second check the stream length, but
I don't know if it is the right approach of if there is an alternative way
I don't know if this may not create some cross-thread errors for the stream
How to detect a transfer failure ?
I guess one of the approaches would be to re-write partially the OneDrive SDK portable project, target only WinRT projects and use Windows.Web objects instead of System.Net, but it seems to be some work for an unsure result.
Any help? :)
You can use the LiveConnectClient class inside the Live SDK instead of downloading the file as a stream and saving it to a file.
Use the BackgroundDownloadAsync(string path, Uri downloadLocation) method to download a file
Begins downloading a file from Microsoft OneDrive to a Windows Phone
isolated storage. [Windows Phone only]
The file download should continue even if the app that starts the file
download quits or is suspended.
Subscribe to the BackgroundDownloadProgressChanged event
Raised at indeterminate times while a file is downloading from Microsoft OneDrive to Windows Phone isolated storage. [Windows Phone only]
Hope it helps!

Get size of a file in Isolated Storage WP 8.0

In a Windows Phone 8.0 application I calculate the size of a file with this following method:
Windows.Storage.FileProperties.BasicProperties props = await thisFile.GetBasicPropertiesAsync();
size = props.Size;
I've read here that this is for Windows Stors apps or WP 8.1 only, not below but it works and I am not getting any Exceptions. Why does it work if it's not supported? Are they going to reject my application submitting to Store?
If it's really not supported, what is the proper way, API to calculate the size of a file in Isolated Storage on WP 8.0?
If it works, it might be the documentation problem and there is no reason to reject your application from the store.

How to execute a background task only for once in windows phone 8.1 universal app

In my application after first login/registration I need to download data from server this will take some time. And user can quit the application while data is loading. So I need to download the data in background process. I know I can use backgorund application/Class and register this class in windows phone application but this is only for one time. Is there any other way to do so without creating backgourd task for this?
Maybe this will help,
You're looking for BackgroundDownloader and DownloadOperation in the Windows.Networking.BackgroundTransfer namespace.
BackgroundDownloader downloader = new BackgroundDownloader();
DownloadOperation download = downloader.CreateDownload(source, destinationFile);
MSDN Windows.Networking.BackgroundTransfer
Background Transfer Sample Project (Windows Universal)

Windows Phone 8 ApplicationSettings - Get settings in Universal app

I'm upgrading windows phone 8 application. I created Universal app (Windows.Phone 8.1).
The settings in old WP8.0 application are saved in following way:
IsolatedStorageSettings.ApplicationSettings.Add("MY_SETTINGS", value);
Question:
How can i get this settings when app is upgraded to WP8.1 (Universal app).
I try the following:
var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
var isContains1 = localSettings.Values.ContainsKey("MY_SETTINGS");
var roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings;
var isContains2 = roamingSettings.Values.ContainsKey("MY_SETTINGS");
But no "MY_SETTINGS" are found. (isContains1, isContains2 == false):\
Many Thanks for help
LocalSettings in WP8.1 works differently than those in WP8.0 - where settings were saved in a file (after serialization). The file is __ApplicationSettings - take a look at it (via IS explorer tool) and you will see its structure - part of it is a serialized dictionary. I've made some research once, which showed that all the old files are preserved during the update - which means that the settings are still there.
Once you update your WP8.0 app to WP8.1 and you want to read your old settings, you can retrive the values from the file.
This blog post has your exact answer, including the code needed to deserialize the migrated settings file!
You can use ApplicationData.LocalSettings It would Get you the application settings container in the local app data store. here is a Dev center link in which its Described how to use it.