Skip to main content

Microsoft Silverlight

Answered Question OpenFileDialog, how check if the file is open by other app?RSS Feed

(0)

dave_600
dave_600

Member

Member

30 points

16 Posts

OpenFileDialog, how check if the file is open by other app?

 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
WilcoB

Member

Member

720 points

137 Posts

Answered Question

Re: OpenFileDialog, how check if the file is open by other app?

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.

- Wilco Bauwer (MSFT) / http://www.wilcob.com
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities