While making a lab on window 8 app dev. I could not load all images needed. So inorder for the share part to work with a sharing imag I need to check if the image file is availeble. The project is a windows grid app using XAML and C# In the past I used
Using System.IO
... lost of code
privat void share()
....
if (File.exist(filename)
{
add file to share
}
If i try this in my window8 project. The File class is not found.
I search the internet but could not find a code example that checkes the existance in a windowsstore app in C#
Michiel
you need StorageFile not File
here is simple example to check and get the file
StorageFile file;
try {
file = await ApplicationData.Current.LocalFolder.GetFileAsync("foo.txt");
}
catch (FileNotFoundException) {
file = null;
}
you can write a function
public static async Task<bool> FileExistsAsync(this StorageFolder folder, string fileName)
{
try
{
await folder.GetFileAsync(fileName);
return true;
}
catch (FileNotFoundException)
{
return false;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With