[英]System.IO.FileNotFoundException: 'The system cannot find the file specified (with SetWallpaperAsync)
I am using the following method to set the background image of my uwp app:我正在使用以下方法来设置我的 uwp 应用程序的背景图像:
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");当我调用 await SetWallpaperAsync("StoreLogo.png"); I get the error "System.IO.FileNotFoundException: 'The system cannot find the file specified".
我收到错误“System.IO.FileNotFoundException:'系统找不到指定的文件”。 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");
当我调用 await SetWallpaperAsync("StoreLogo.png"); I get the error "System.IO.FileNotFoundException,but I have no idea where to put it.
我收到错误“System.IO.FileNotFoundException,但我不知道该放在哪里。
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.您可以使用
ms-appdata:///local/
uri 方案访问本地应用程序数据存储中的文件。 For example:例如:
ms-appdata:///local/myBinaryFile
And you could also use ApplicationData.Current.LocalFolder API the get file您还可以使用ApplicationData.Current.LocalFolder API 获取文件
Use the ms-appx
URI scheme to refer to a file that comes from your app's package .使用
ms-appx
URI 方案来引用来自应用程序 package 的文件。 and you could also use InstalledLocation
API.您也可以使用
InstalledLocation
API。
For more detail, you could refer URI schemes有关更多详细信息,您可以参考URI 方案
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.