I am trying to write a routine to check if a file exists in a application package. After reading a lot on the subject it's obvious that MS forgot to put a FileExists function in the API (deliberate or not) but here is where I am at so far...
public async Task<bool> CheckFile(string filePath)
{
bool found = false;
try
{
Windows.ApplicationModel.Package package = Windows.ApplicationModel.Package.Current;
Windows.Storage.StorageFolder installedLocation = package.InstalledLocation;
StorageFile file = await installedLocation.GetFileAsync("Assets\\" + filePath);
found = true;
}
catch (System.IO.FileNotFoundException ex)
{
found = false;
}
return found;
}
and then called from:
private ImageSource _image = null;
private String _imagePath = null;
public ImageSource Image
{
get
{
if (this._image == null && this._imagePath != null)
{
Task<bool> fileExists = CheckFile(this._imagePath);
bool filefound = fileExists.Result;
string realPath = string.Empty;
if (filefound)
{
Windows.ApplicationModel.Package package = Windows.ApplicationModel.Package.Current;
Windows.Storage.StorageFolder installedLocation = package.InstalledLocation;
realPath = installedLocation + "Assets\\" + this._imagePath;
}
else
{
realPath = "http://<<my url>>/images/" + this._imagePath;
}
this._image = new BitmapImage(new Uri(realPath));
}
return this._image;
}
set
{
this._imagePath = null;
this.SetProperty(ref this._image, value);
}
}
SO basically it's a check to see if an image exists locally and if not then go get it from my website.
It all seems to work fine for the first image but then when it gets to "return this._image;" for the second image everything just freezes...
I'm just not sure what's going on here really..
Any help?
Cheers Dean