Hello,
For the legitimacy verification of a file, the file method usually verifies its legitimacy and is not a handling exception.
Before setting the file path, you could use the File.Exists
method to determine whether the file exists to avoid this exception.
var path = media_path;
if (File.Exists(path))
{
media.Source = path;
}
else
{
Console.WriteLine("file does not exist");
}
Best Regards,
Alec Liu.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.