locked
File Exists Question

    Question

  • I am not a big fan exception handling to determine the existence of the file. I realize that there are threading issues that complicate the verification of file existence. I tried to make use isavailable below but it obviously still creates an exception.
    When I run my project in Visual Studio the output window gets polluted with all kinds of exceptions. Is there a better way? Am I stuck with exception handling?

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
            async public Task<bool> MyFileExists(StorageFolder folder, string fileName)
            {
                try
                {
                    StorageFile sf = await StorageFile.GetFileFromPathAsync(folder.Path.AddSlash() + fileName);
                    return sf.IsAvailable;
                }
                catch (FileNotFoundException)
                {
                    return false;
                }
            }

    Bruno Terkaly

    Wednesday, February 19, 2014 6:17 PM

Answers

All replies