Check for ReadOnly File is in Use

  • Thread starter Mayur H Chauhan
  • Start date
M

Mayur H Chauhan

All,
I am working on one product where we need to check for physical file
is in use (if it is open by other application). What I found out is that I
am able to trap for those files whose attribute is not Set as ReadOnly. I
have done this by opening file using FileStream Object opening in Edit mode
with No Shared. But if I am try to apply same logic for ReadOnly files, then
it throws NonAuthorized exception. This exception is also raised even when I
try to open this file even if this is not in use by other application.

Any suggestion would be helpful

Thanks
Mayur Chauhan
 
J

J T

Here is the code : you can check FileAttribute

Imports System.IO

Dim Filepath as string = "c:\\myFile.txt"

If (File.GetAttributes(Filepath)) Then
If (FileAttributes.ReadOnly = FileAttributes.ReadOnly) Then
MsgBox("File is read only")
End If
End If
 
J

JT

Here is the code : You can use FileAttributes to do this

Imports System.IO
Dim Filepath as string = "c:\\myFile.txt"
If (File.GetAttributes(Filepath)) Then
If (FileAttributes.ReadOnly = FileAttributes.ReadOnly) Then
MsgBox("File is readd only")
End If
End If
 
M

Mayur H Chauhan

Thanks for you reply.
But here what I want to know is whether ReadOnly file is currently Open or
not. In Other words, Whether ReadOnly file is currently used by any other
application.


--
Thanks and Regards,
Mayur H Chauhan

Software Developer
www.myarcane.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top