Windows Store App – Check If File Exist or Not

Before Windows 8, to check a file exist or not on Windows Phone 7.5 or .NET can be as simple as calling the file.IsFileExist() and it will return a simple boolean indicated whatever the file exist or not. But Windows 8 team decided to have a totally different way and I had no idea why Microsoft or Windows 8 team decided to re-write it.

Anyway, here is how it work out in Windows 8 app (C# code):

public async Task<bool> IsFileExist(string path)
{
    try
    {
        await Windows.Storage.StorageFile.GetFileFromPathAsync(path);

        // file found
        return (true);
    }
    catch
    {
        // file not found
        return (false);
    }
}

 

by Ooi Keng Siang via Ooiks’s Blog

One thought on “Windows Store App – Check If File Exist or Not

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s