protected virtual async void updateAvatarSource() { if (Avatar == "") { return; } var localFolder = ApplicationData.Current.LocalFolder; string filename = Avatar.Substring(Avatar.LastIndexOfAny(new char[2] { '/', '\\' }) + 1); // If the file is not exist, create one. StorageFile avatarFile; try { avatarFile = await localFolder.GetFileAsync(filename); } catch (FileNotFoundException e) { Debug.WriteLine(e.Message); avatarFile = await localFolder.CreateFileAsync(filename); } catch (Exception e) { Debug.WriteLine(e.Message); return; } // Download file from web IBuffer downloadedBuffer = await HTTP.GetAvatar(Avatar); try { // Store downloaded content into file Stream writeStream = await avatarFile.OpenStreamForWriteAsync(); await writeStream.AsOutputStream().WriteAsync(downloadedBuffer); await writeStream.AsOutputStream().FlushAsync(); writeStream.AsOutputStream().Dispose(); // Read content and add it to source BitmapImage source = new BitmapImage(); IRandomAccessStream ras = await avatarFile.OpenReadAsync(); await source.SetSourceAsync(ras); AvatarSource = source; } catch (Exception e) { Debug.WriteLine(e.Message); } }