Re: Check for ReadOnly File is in Use by Mayur
Mayur
Mon May 12 10:05:22 CDT 2008
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
"JT" <JT@discussions.microsoft.com> wrote in message
news:E02197DB-CDA5-4CA2-9BD4-CE3AD26B8022@microsoft.com...
> 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
>
> "Mayur H Chauhan" wrote:
>
>> 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
>>
>>
>>