简体   繁体   English

System.IO.FileNotFoundException: '系统找不到指定的文件(使用 SetWallpaperAsync)

[英]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.

相关问题 System.IO.FileNotFoundException:系统找不到指定的文件。 在IIS 7中(Web服务项目) - System.IO.FileNotFoundException: The system cannot find the file specified. in IIS 7 (web service project) System.IO.FileNotFoundException:无法找到上载的文件 - System.IO.FileNotFoundException : Cannot able to find the uploaded file System.IO.FileNotFoundException:找不到文件 - System.IO.FileNotFoundException : Could not find file System.IO.FileNotFoundException - 系统找不到指定的路径? - System.IO.FileNotFoundException - the system could not find the path specified? VSTO错误System.IO.FileNotFoundException:系统找不到指定的文件。 (来自HRESULT的异常:0x80070002) - VSTO Error System.IO.FileNotFoundException: The system cannot find the file specified. (Exception from HRESULT: 0x80070002) System.IO.FileNotFoundException:无法加载文件或程序集。 系统找不到文件SharpSvn.dll - System.IO.FileNotFoundException: Could not load file or assembly. The system cannot find the file SharpSvn.dll NamedPipeClientStream.Connect()抛出System.IO.FileNotFoundException:无法找到指定的文件 - NamedPipeClientStream.Connect() throws System.IO.FileNotFoundException: Unable to find the specified file &#39;System.IO.FileNotFoundException&#39; - 'System.IO.FileNotFoundException' System.IO.FileNotFoundException - System.IO.FileNotFoundException Xamarin Android System.IO.FileNotFoundException:找不到文件异常 - Xamarin Android System.IO.FileNotFoundException: Could not find file Exception
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM