Basically I'm trying to set a Windows 8 account picture from a "Console Application". The only API to set the picture that I found is in the WinRT API. So after blood, sweat, and tears I finally managed to get a hybrid .NET/WinRT somewhat working, but the clue being that it doesn't actually work.
Anyway, this is the code so far:
The SetAccountPictureResult says 'failure' without any other information. What could be happening here?Code:private static async Task SetAccountPicture(string employeeId) { // Download image string imagePath = DownloadImage(employeeId); // Set account picture Stream fileStream = File.Open(imagePath, FileMode.Open); IRandomAccessStream winRTStream = await DotNetToWinRTStream(fileStream); SetAccountPictureResult result = await UserInformation.SetAccountPicturesFromStreamsAsync(null, winRTStream, null); // Clean up download file File.Delete(imagePath); } public static async Task<IRandomAccessStream> DotNetToWinRTStream(Stream dotNetStream) { IBuffer buffer; var inputStream = dotNetStream.AsInputStream(); using (var reader = new DataReader(inputStream)) { await reader.LoadAsync((uint)dotNetStream.Length); buffer = reader.DetachBuffer(); } var memoryStream = new InMemoryRandomAccessStream(); await memoryStream.WriteAsync(buffer); return memoryStream; }




Reply With Quote