public async Task <Foto> GetSponsorImageAsync(Guid verenigingId, Guid afbeeldingId) { Foto foto = new Foto(); StorageFile image = null; Sponsor sponsor = _cachedSponsors.SingleOrDefault(s => s.AfbeeldingId == afbeeldingId); //StorageFolder _folder = Windows.Storage.ApplicationData.Current.TemporaryFolder; //StorageFolder _fotos = await _folder.CreateFolderAsync("Sponsors", CreationCollisionOption.OpenIfExists); //string _filename = sponsorId + ".jpg"; //image = await _fotos.CreateFileAsync(_filename, CreationCollisionOption.ReplaceExisting); //foto.Path = image.Path; if (sponsor != null) { string filename = sponsor.Id + ".jpg"; StorageFolder folder = Windows.Storage.ApplicationData.Current.TemporaryFolder; StorageFolder fotos = await folder.CreateFolderAsync("Sponsors", CreationCollisionOption.OpenIfExists); image = await fotos.TryGetItemAsync(filename) as StorageFile; try { if (image != null) { await image.DeleteAsync(StorageDeleteOption.PermanentDelete); } if (image == null) { foto = await _sponsorService.GetSponsorImageByIdAsync(verenigingId, afbeeldingId); if (foto != null) { image = await fotos.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting); IBuffer writebuffer = GetBufferFromContentData(foto.ContentData); await Windows.Storage.FileIO.WriteBufferAsync(image, writebuffer); foto.Path = image.Path; } } } catch (Exception ex) { string message = ex.Message; } /* * try * { * IBuffer readbuffer = await FileIO.ReadBufferAsync(image); * * if (foto.ContentData != null) * foto.ContentData = new byte[readbuffer.Length]; * * foto.ContentData = readbuffer.ToArray(); * } * catch (Exception ex) * { * string message = ex.Message; * } */ } return(foto); }