I am developing an app using windows 10 SDK and I want to use Live SDK. I am using VS 2015 and I have installed Live SDK through nuget.
Following code has been taken from MSDN sample code:
LiveConnectClient liveClient;
private async Task<int> UploadFileToOneDrive()
{
try
{
// create OneDrive auth client
var authClient = new LiveAuthClient();
// ask for both read and write access to the OneDrive
LiveLoginResult result = await authClient.LoginAsync(new string[] { "wl.skydrive", "wl.skydrive_update" });
// if login successful
if (result.Status == LiveConnectSessionStatus.Connected)
{
// create a OneDrive client
liveClient = new LiveConnectClient(result.Session);
// create a local file
StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync("filename", CreationCollisionOption.ReplaceExisting);
// copy some txt to local file
MemoryStream ms = new MemoryStream();
DataContractSerializer serializer = new DataContractSerializer(typeof(string));
serializer.WriteObject(ms, "Hello OneDrive World!!");
using (Stream fileStream = await file.OpenStreamForWriteAsync())
{
ms.Seek(0, SeekOrigin.Begin);
await ms.CopyToAsync(fileStream);
await fileStream.FlushAsync();
}
// create a folder
string folderID = await GetFolderID("folderone");
if (string.IsNullOrEmpty(folderID))
{
// return error
return 0;
}
// upload local file to OneDrive
await liveClient.BackgroundUploadAsync(folderID, file.Name, file, OverwriteOption.Overwrite);
return 1;
}
}
catch
{
}
// return error
return 0;
}
public async Task<int> DownloadFileFromOneDrive()
{
try
{
string fileID = string.Empty;
// get folder ID
string folderID = await GetFolderID("folderone");
if (string.IsNullOrEmpty(folderID))
{
return 0; // doesnt exists
}
// get list of files in this folder
LiveOperationResult loResults = await liveClient.GetAsync(folderID + "/files");
List<object> folder = loResults.Result["data"] as List<object>;
// search for our file
foreach (object fileDetails in folder)
{
IDictionary<string, object> file = fileDetails as IDictionary<string, object>;
if (string.Compare(file["name"].ToString(), "filename", StringComparison.OrdinalIgnoreCase) == 0)
{
// found our file
fileID = file["id"].ToString();
break;
}
}
if (string.IsNullOrEmpty(fileID))
{
// file doesnt exists
return 0;
}
// create local file
StorageFile localFile = await ApplicationData.Current.LocalFolder.CreateFileAsync("filename_from_onedrive", CreationCollisionOption.ReplaceExisting);
// download file from OneDrive
await liveClient.BackgroundDownloadAsync(fileID + "/content", localFile);
return 1;
}
catch
{
}
return 0;
}
Problem is that even after installing nuget, LiveConnectClient is not getting recognised. Its assembly reference is missing. When I tried setting it manually by adding the reference, it is still not getting resolved. (Could it be meant only for windows 8?)
The Live SDK information is shown in the image below:
The Live SDK is from here: https://github.com/liveservices/LiveSDK-for-Windows
What am I missing here?
It's probably a Nuget package problem, hence adding a reference manually seems to resolve the issue. You will find the reference in:
C:\Users\USER\.nuget\packages\LiveSDK\5.6.3\WindowsXAML\MicrosoftLive.dll