I am using the following method to set the background image of my uwp app:
async Task<bool> SetWallpaperAsync(string localAppDataFileName)
{
bool success = false;
if (UserProfilePersonalizationSettings.IsSupported())
{
var uri = new Uri("ms-appx:///Local/" + localAppDataFileName);
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(uri);
UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current;
success = await profileSettings.TrySetLockScreenImageAsync(file);
}
return success;
}
When I call await SetWallpaperAsync("StoreLogo.png"); I get the error "System.IO.FileNotFoundException: 'The system cannot find the file specified". I'm guessing the problem is that I have the file stored in the wrong place but I have no idea where to put it.
When I call await SetWallpaperAsync("StoreLogo.png"); I get the error "System.IO.FileNotFoundException,but I have no idea where to put it.
The problem is that you get file with wrong path. You can access files in the local app data store using the ms-appdata:///local/
uri scheme. For example:
ms-appdata:///local/myBinaryFile
And you could also use ApplicationData.Current.LocalFolder API the get file
Use the ms-appx
URI scheme to refer to a file that comes from your app's package . and you could also use InstalledLocation
API.
For more detail, you could refer URI schemes
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.