相关疑难解决方法(0)

检查WinRT中的项目中是否存在文件

我有一个WinRT Metro项目,它根据所选项目显示图像.但是,某些选定的图像将不存在.我想要做的是陷入不存在的情况并显示替代方案.

到目前为止,这是我的代码:

internal string GetMyImage(string imageDescription)
{
    string myImage = string.Format("Assets/MyImages/{0}.jpg", imageDescription.Replace(" ", ""));

    // Need to check here if the above asset actually exists

    return myImage;
}
Run Code Online (Sandbox Code Playgroud)

示例调用:

GetMyImage("First Picture");
GetMyImage("Second Picture");
Run Code Online (Sandbox Code Playgroud)

所以Assets/MyImages/SecondPicture.jpg存在,但Assets/MyImages/FirstPicture.jpg没有.

起初我想过使用WinRT相当于File.Exists(),但似乎没有.无需尝试打开文件并捕获错误,我可以简单地检查文件是否存在,或者文件是否存在于项目中?

windows-8 windows-runtime windows-store-apps

12
推荐指数
2
解决办法
1万
查看次数