Reputation: 302
Searching on the web I found this code UWP, to get the image but I'm not be able to include namespace Windows.Storage in WPF. I tried to include all possible references but doesn't work. I would have a solution WPF to include Windows.Storage(if possible) or simply another way to implement code to get image
StorageFile image = UserInformation.GetAccountPicture(AccountPictureKind.SmallImage) as StorageFile;
if (image != null)
{
rootPage.NotifyUser("SmallImage path = " + image.Path, NotifyType.StatusMessage);
}
else
{
rootPage.NotifyUser("Small Account Picture is not available", NotifyType.StatusMessage);
mediaPlayer.Visibility = Visibility.Collapsed;
smallImage.Visibility = Visibility.Collapsed;
largeImage.Visibility = Visibility.Collapsed;
}
Upvotes: 0
Views: 1305
Reputation: 2171
Based on this answer if you take a look here
As long as you have the currently logged in username, you should be able to access it. This is the case for Win OS 7 at least, I don't know which OS you're working with.
Upvotes: 0
Reputation: 169420
The Windows.System.UserProfile
namespace is for UWP app development and does not apply to WPF.
You may be able to use it if you package (convert) your app to UWP: https://learn.microsoft.com/sv-se/windows/uwp/porting/desktop-to-uwp-supported-api#apis-supported-in-both-converted-apps-and-desktop-applications. Note that the UserInformation
class is not supported on Windows 10 or later. Instead, you should use the User class.
In a .NET application, you could try to search the C:\Users\<user>\AppData\Roaming\Microsoft\Windows\Account Pictures
folder for the latest modified file:
How to find the most recent file in a directory using .NET, and without looping?
Upvotes: 2