Skip to main content
Home Forums Silverlight Programming Programming with .NET - General OpenFileDialog, how check if the file is open by other app?
1 replies. Latest Post by WilcoB on April 9, 2008.
(0)
dave_600
Member
30 points
16 Posts
04-09-2008 4:23 PM |
If using the OpenFileDialog to select a file, and if the file is open in other app, the read will fail.
is there a way to check if it is readable before read it?
if (ofd.ShowDialog() == DialogResult.OK)
{
Stream stream = ofd.SelectedFile.OpenRead(); <== exception
}
Thanks!
WilcoB
720 points
137 Posts
04-09-2008 7:54 PM |
You will have to assume reading may fail. There are at least a couple of cases where it may fail:1. The file is exclusively opened by another app.2. The file no longer exists.
In other words, you'll want to handle any exceptions that are thrown and handle those.