<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: detecting a file in use in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/detecting-a-file-in-use/m-p/2624730#M67295</link>
    <description>{quote}&lt;BR /&gt;
&lt;BR /&gt;
Opened file in Notepad and then tried to open it at the same time in Excel.&lt;BR /&gt;
Got a message that the file is in use by another user.&lt;BR /&gt;
&lt;BR /&gt;
{quote}&lt;BR /&gt;
&lt;BR /&gt;
It doesn't work that way here.  I open a file with notepad, then&lt;BR /&gt;
opened the same file with Excel and the file opens in both.&lt;BR /&gt;
&lt;BR /&gt;
Regardless of that, none of this makes any sense.&lt;BR /&gt;
&lt;BR /&gt;
If you are going to delete the file, then you can try to delete it,&lt;BR /&gt;
and if for any reason you can't, there will be an exception thrown&lt;BR /&gt;
that you can catch, so what's the problem?&lt;BR /&gt;
&lt;BR /&gt;
If you only want to know if a file can be deleted, you can use the&lt;BR /&gt;
File.Move() method to rename the file, and catch the exception&lt;BR /&gt;
that's thrown if the file can't be deleted, and if there is no exception&lt;BR /&gt;
you can rename the file back to the original name, and then you&lt;BR /&gt;
know if the file can be deleted without actually doing it.&lt;BR /&gt;
&lt;BR /&gt;
Whether a file is 'in use' or not depends on whether the application&lt;BR /&gt;
that opens the file specifies that the file can't be accessed at all, or&lt;BR /&gt;
accessed for reading only.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD&lt;BR /&gt;
Supporting AutoCAD 2000 through 2010&lt;BR /&gt;
&lt;BR /&gt;
http://www.acadxtabs.com&lt;BR /&gt;
&lt;BR /&gt;
Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");&lt;BR /&gt;
&lt;BR /&gt;
"Ray S Whitmore" &lt;RAY&gt; wrote in message&lt;BR /&gt;
news:6327623@discussion.autodesk.com...&lt;BR /&gt;
This is getting interesting (and confusing). Tried the following code:&lt;BR /&gt;
&lt;BR /&gt;
Try&lt;BR /&gt;
   Dim file As FileStream&lt;BR /&gt;
   file = New FileStream("c:\test.txt", FileMode.Append, FileAccess.Write)&lt;BR /&gt;
   FileClose()&lt;BR /&gt;
   MsgBox("file can be deleted")&lt;BR /&gt;
Catch&lt;BR /&gt;
   MsgBox("file cannot be deleted")&lt;BR /&gt;
End Try&lt;BR /&gt;
&lt;BR /&gt;
It indicated that the file could be deleted whether the file was currently&lt;BR /&gt;
open in Notepad or not.&lt;BR /&gt;
&lt;BR /&gt;
Opened the file in Excel and then ran the above code - works as desired.&lt;BR /&gt;
&lt;BR /&gt;
Opened file in Notepad and then tried to open it at the same time in Excel.&lt;BR /&gt;
Got a message that the file is in use by another user.&lt;BR /&gt;
&lt;BR /&gt;
So Excel can detect that the file is open by another user but my routine&lt;BR /&gt;
does not. Do you know of another way to test the file?&lt;BR /&gt;
&lt;BR /&gt;
"Tony Tanzillo" &lt;TONY.TANZILLO&gt; wrote in message&lt;BR /&gt;
news:6327450@discussion.autodesk.com...&lt;BR /&gt;
You're confusing two different things.&lt;BR /&gt;
&lt;BR /&gt;
The readonly attribute of a file means the file is read-only&lt;BR /&gt;
and can't be written to.&lt;BR /&gt;
&lt;BR /&gt;
You can open any file in notepad, read-only or not, but&lt;BR /&gt;
you can't save changes to it in notepad if it's read-only.&lt;BR /&gt;
&lt;BR /&gt;
Notepad doesn't put any kind of lock on a file when it&lt;BR /&gt;
opens it, it just reads the file and displays its contents,&lt;BR /&gt;
and doesn't access the file again until you try to save.&lt;BR /&gt;
&lt;BR /&gt;
The standard test for detecting if a file is writeable is&lt;BR /&gt;
to open it for write, using "append" mode, which will&lt;BR /&gt;
not erase the existing file's contents if it succeeds,&lt;BR /&gt;
and then immediately close the file if the open succeeds&lt;BR /&gt;
(which means the file is writeable).&lt;BR /&gt;
&lt;BR /&gt;
I don't know what that Notepad nonsense in the other&lt;BR /&gt;
post is about, but you really should avoid cheesy hacks&lt;BR /&gt;
like that, like the plauge.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD&lt;BR /&gt;
Supporting AutoCAD 2000 through 2010&lt;BR /&gt;
&lt;BR /&gt;
http://www.acadxtabs.com&lt;BR /&gt;
&lt;BR /&gt;
Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");&lt;BR /&gt;
&lt;BR /&gt;
"Ray S Whitmore" &lt;RAY&gt; wrote in message&lt;BR /&gt;
news:6327347@discussion.autodesk.com...&lt;BR /&gt;
I'm trying to delete an existing file and need to detect whether it is&lt;BR /&gt;
currently open by another program. The following is a snippet of code I&lt;BR /&gt;
tested it with:&lt;BR /&gt;
Public Sub TestReadOnly&lt;BR /&gt;
&lt;BR /&gt;
   Dim CheckFile As New IO.FileInfo("c:\test.txt")&lt;BR /&gt;
&lt;BR /&gt;
   MsgBox("IsReadOnly = " &amp;amp; CheckFile.IsReadOnly)&lt;BR /&gt;
&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
I open the test.txt file in Notepad and then run the above in AutoCAD. The&lt;BR /&gt;
Msgbox says IsReadOnly = false. I would expect it to be true.&lt;BR /&gt;
&lt;BR /&gt;
I'm stumped.&lt;/RAY&gt;&lt;/TONY.TANZILLO&gt;&lt;/RAY&gt;</description>
    <pubDate>Mon, 01 Feb 2010 01:37:14 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2010-02-01T01:37:14Z</dc:date>
    <item>
      <title>detecting a file in use</title>
      <link>https://forums.autodesk.com/t5/net-forum/detecting-a-file-in-use/m-p/2624724#M67289</link>
      <description>I'm trying to delete an existing file and need to detect whether it is &lt;BR /&gt;
currently open by another program. The following is a snippet of code I &lt;BR /&gt;
tested it with:&lt;BR /&gt;
Public Sub TestReadOnly&lt;BR /&gt;
&lt;BR /&gt;
   Dim CheckFile As New IO.FileInfo("c:\test.txt")&lt;BR /&gt;
&lt;BR /&gt;
   MsgBox("IsReadOnly = " &amp;amp; CheckFile.IsReadOnly)&lt;BR /&gt;
&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
I open the test.txt file in Notepad and then run the above in AutoCAD. The &lt;BR /&gt;
Msgbox says IsReadOnly = false. I would expect it to be true.&lt;BR /&gt;
&lt;BR /&gt;
I'm stumped.</description>
      <pubDate>Fri, 29 Jan 2010 23:35:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/detecting-a-file-in-use/m-p/2624724#M67289</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-01-29T23:35:31Z</dc:date>
    </item>
    <item>
      <title>Re: detecting a file in use</title>
      <link>https://forums.autodesk.com/t5/net-forum/detecting-a-file-in-use/m-p/2624725#M67290</link>
      <description>The issue is notepad will not lock the file. &lt;BR /&gt;
You will need to check the process list and see if the file is currently opened. &lt;BR /&gt;
&lt;BR /&gt;
{code}&lt;BR /&gt;
Public Class TextFile&lt;BR /&gt;
 &lt;BR /&gt;
   Sub RunIt()&lt;BR /&gt;
        MsgBox(isTextFileInUse("c:\test1.txt"))&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
    Function isTextFileInUse(ByVal FullPath As String) As Boolean&lt;BR /&gt;
        Dim FileName As String = ""&lt;BR /&gt;
        If Not isFileInUse(FullPath) Then&lt;BR /&gt;
            FileName = System.IO.Path.GetFileName(FullPath)&lt;BR /&gt;
            If CheckNotepad(FileName) Then&lt;BR /&gt;
                Return True&lt;BR /&gt;
            End If&lt;BR /&gt;
        Else&lt;BR /&gt;
            Return True&lt;BR /&gt;
        End If&lt;BR /&gt;
        Return False&lt;BR /&gt;
    End Function&lt;BR /&gt;
&lt;BR /&gt;
    Public Function isFileInUse(ByVal sFile As String) As Boolean&lt;BR /&gt;
        If System.IO.File.Exists(sFile) Then&lt;BR /&gt;
            Try&lt;BR /&gt;
                Dim F As Short = FreeFile()&lt;BR /&gt;
                FileOpen(F, sFile, OpenMode.Binary, OpenAccess.ReadWrite, OpenShare.LockReadWrite)&lt;BR /&gt;
                FileClose(F)&lt;BR /&gt;
            Catch&lt;BR /&gt;
                Return True&lt;BR /&gt;
            End Try&lt;BR /&gt;
        End If&lt;BR /&gt;
    End Function&lt;BR /&gt;
&lt;BR /&gt;
    Function CheckNotepad(ByVal textFile As String) As Boolean&lt;BR /&gt;
        Dim ProcessList As System.Diagnostics.Process()&lt;BR /&gt;
        Dim Proc As System.Diagnostics.Process&lt;BR /&gt;
&lt;BR /&gt;
        Dim rtnValue As Boolean = False&lt;BR /&gt;
        ProcessList = System.Diagnostics.Process.GetProcesses()&lt;BR /&gt;
        Try&lt;BR /&gt;
            For Each Proc In ProcessList&lt;BR /&gt;
                If Proc.ProcessName.ToUpper = "NOTEPAD" Then&lt;BR /&gt;
                    If Proc.MainWindowTitle.Substring(0, textFile.Length).ToUpper = textFile.ToUpper Then&lt;BR /&gt;
                        rtnValue = True&lt;BR /&gt;
                        Exit For&lt;BR /&gt;
                    End If&lt;BR /&gt;
                End If&lt;BR /&gt;
            Next&lt;BR /&gt;
        Catch ex As Exception&lt;BR /&gt;
        End Try&lt;BR /&gt;
        Return rtnValue&lt;BR /&gt;
    End Function&lt;BR /&gt;
&lt;BR /&gt;
End Class&lt;BR /&gt;
{code}</description>
      <pubDate>Sat, 30 Jan 2010 06:02:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/detecting-a-file-in-use/m-p/2624725#M67290</guid>
      <dc:creator>arcticad</dc:creator>
      <dc:date>2010-01-30T06:02:17Z</dc:date>
    </item>
    <item>
      <title>Re: detecting a file in use</title>
      <link>https://forums.autodesk.com/t5/net-forum/detecting-a-file-in-use/m-p/2624726#M67291</link>
      <description>You're confusing two different things.&lt;BR /&gt;
&lt;BR /&gt;
The readonly attribute of a file means the file is read-only&lt;BR /&gt;
and can't be written to.&lt;BR /&gt;
&lt;BR /&gt;
You can open any file in notepad, read-only or not, but&lt;BR /&gt;
you can't save changes to it in notepad if it's read-only.&lt;BR /&gt;
&lt;BR /&gt;
Notepad doesn't put any kind of lock on a file when it&lt;BR /&gt;
opens it, it just reads the file and displays its contents,&lt;BR /&gt;
and doesn't access the file again until you try to save.&lt;BR /&gt;
&lt;BR /&gt;
The standard test for detecting if a file is writeable is&lt;BR /&gt;
to open it for write, using "append" mode, which will&lt;BR /&gt;
not erase the existing file's contents if it succeeds,&lt;BR /&gt;
and then immediately close the file if the open succeeds&lt;BR /&gt;
(which means the file is writeable).&lt;BR /&gt;
&lt;BR /&gt;
I don't know what that Notepad nonsense in the other&lt;BR /&gt;
post is about, but you really should avoid cheesy hacks&lt;BR /&gt;
like that, like the plauge.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD&lt;BR /&gt;
Supporting AutoCAD 2000 through 2010&lt;BR /&gt;
&lt;BR /&gt;
http://www.acadxtabs.com&lt;BR /&gt;
&lt;BR /&gt;
Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");&lt;BR /&gt;
&lt;BR /&gt;
"Ray S Whitmore" &lt;RAY&gt; wrote in message &lt;BR /&gt;
news:6327347@discussion.autodesk.com...&lt;BR /&gt;
I'm trying to delete an existing file and need to detect whether it is&lt;BR /&gt;
currently open by another program. The following is a snippet of code I&lt;BR /&gt;
tested it with:&lt;BR /&gt;
Public Sub TestReadOnly&lt;BR /&gt;
&lt;BR /&gt;
   Dim CheckFile As New IO.FileInfo("c:\test.txt")&lt;BR /&gt;
&lt;BR /&gt;
   MsgBox("IsReadOnly = " &amp;amp; CheckFile.IsReadOnly)&lt;BR /&gt;
&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
I open the test.txt file in Notepad and then run the above in AutoCAD. The&lt;BR /&gt;
Msgbox says IsReadOnly = false. I would expect it to be true.&lt;BR /&gt;
&lt;BR /&gt;
I'm stumped.&lt;/RAY&gt;</description>
      <pubDate>Sat, 30 Jan 2010 12:44:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/detecting-a-file-in-use/m-p/2624726#M67291</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-01-30T12:44:00Z</dc:date>
    </item>
    <item>
      <title>Re: detecting a file in use</title>
      <link>https://forums.autodesk.com/t5/net-forum/detecting-a-file-in-use/m-p/2624727#M67292</link>
      <description>This is getting interesting (and confusing). Tried the following code:&lt;BR /&gt;
&lt;BR /&gt;
Try&lt;BR /&gt;
   Dim file As FileStream&lt;BR /&gt;
   file = New FileStream("c:\test.txt", FileMode.Append, FileAccess.Write)&lt;BR /&gt;
   FileClose()&lt;BR /&gt;
   MsgBox("file can be deleted")&lt;BR /&gt;
Catch&lt;BR /&gt;
   MsgBox("file cannot be deleted")&lt;BR /&gt;
End Try&lt;BR /&gt;
&lt;BR /&gt;
It indicated that the file could be deleted whether the file was currently &lt;BR /&gt;
open in Notepad or not.&lt;BR /&gt;
&lt;BR /&gt;
Opened the file in Excel and then ran the above code - works as desired.&lt;BR /&gt;
&lt;BR /&gt;
Opened file in Notepad and then tried to open it at the same time in Excel. &lt;BR /&gt;
Got a message that the file is in use by another user.&lt;BR /&gt;
&lt;BR /&gt;
So Excel can detect that the file is open by another user but my routine &lt;BR /&gt;
does not. Do you know of another way to test the file?&lt;BR /&gt;
&lt;BR /&gt;
"Tony Tanzillo" &lt;TONY.TANZILLO&gt; wrote in message &lt;BR /&gt;
news:6327450@discussion.autodesk.com...&lt;BR /&gt;
You're confusing two different things.&lt;BR /&gt;
&lt;BR /&gt;
The readonly attribute of a file means the file is read-only&lt;BR /&gt;
and can't be written to.&lt;BR /&gt;
&lt;BR /&gt;
You can open any file in notepad, read-only or not, but&lt;BR /&gt;
you can't save changes to it in notepad if it's read-only.&lt;BR /&gt;
&lt;BR /&gt;
Notepad doesn't put any kind of lock on a file when it&lt;BR /&gt;
opens it, it just reads the file and displays its contents,&lt;BR /&gt;
and doesn't access the file again until you try to save.&lt;BR /&gt;
&lt;BR /&gt;
The standard test for detecting if a file is writeable is&lt;BR /&gt;
to open it for write, using "append" mode, which will&lt;BR /&gt;
not erase the existing file's contents if it succeeds,&lt;BR /&gt;
and then immediately close the file if the open succeeds&lt;BR /&gt;
(which means the file is writeable).&lt;BR /&gt;
&lt;BR /&gt;
I don't know what that Notepad nonsense in the other&lt;BR /&gt;
post is about, but you really should avoid cheesy hacks&lt;BR /&gt;
like that, like the plauge.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD&lt;BR /&gt;
Supporting AutoCAD 2000 through 2010&lt;BR /&gt;
&lt;BR /&gt;
http://www.acadxtabs.com&lt;BR /&gt;
&lt;BR /&gt;
Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");&lt;BR /&gt;
&lt;BR /&gt;
"Ray S Whitmore" &lt;RAY&gt; wrote in message&lt;BR /&gt;
news:6327347@discussion.autodesk.com...&lt;BR /&gt;
I'm trying to delete an existing file and need to detect whether it is&lt;BR /&gt;
currently open by another program. The following is a snippet of code I&lt;BR /&gt;
tested it with:&lt;BR /&gt;
Public Sub TestReadOnly&lt;BR /&gt;
&lt;BR /&gt;
   Dim CheckFile As New IO.FileInfo("c:\test.txt")&lt;BR /&gt;
&lt;BR /&gt;
   MsgBox("IsReadOnly = " &amp;amp; CheckFile.IsReadOnly)&lt;BR /&gt;
&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
I open the test.txt file in Notepad and then run the above in AutoCAD. The&lt;BR /&gt;
Msgbox says IsReadOnly = false. I would expect it to be true.&lt;BR /&gt;
&lt;BR /&gt;
I'm stumped.&lt;/RAY&gt;&lt;/TONY.TANZILLO&gt;</description>
      <pubDate>Sun, 31 Jan 2010 15:08:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/detecting-a-file-in-use/m-p/2624727#M67292</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-01-31T15:08:58Z</dc:date>
    </item>
    <item>
      <title>Re: detecting a file in use</title>
      <link>https://forums.autodesk.com/t5/net-forum/detecting-a-file-in-use/m-p/2624728#M67293</link>
      <description>Seems like a lot of trouble to go through but it works and works well. If &lt;BR /&gt;
nothing else, this environment is verbose. Thank you.&lt;BR /&gt;
&lt;BR /&gt;
&lt;ARCTICAD&gt; wrote in message news:6327410@discussion.autodesk.com...&lt;BR /&gt;
The issue is notepad will not lock the file.&lt;BR /&gt;
You will need to check the process list and see if the file is currently &lt;BR /&gt;
opened.&lt;BR /&gt;
&lt;BR /&gt;
{code}&lt;BR /&gt;
Public Class TextFile&lt;BR /&gt;
&lt;BR /&gt;
   Sub RunIt()&lt;BR /&gt;
        MsgBox(isTextFileInUse("c:\test1.txt"))&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
    Function isTextFileInUse(ByVal FullPath As String) As Boolean&lt;BR /&gt;
        Dim FileName As String = ""&lt;BR /&gt;
        If Not isFileInUse(FullPath) Then&lt;BR /&gt;
            FileName = System.IO.Path.GetFileName(FullPath)&lt;BR /&gt;
            If CheckNotepad(FileName) Then&lt;BR /&gt;
                Return True&lt;BR /&gt;
            End If&lt;BR /&gt;
        Else&lt;BR /&gt;
            Return True&lt;BR /&gt;
        End If&lt;BR /&gt;
        Return False&lt;BR /&gt;
    End Function&lt;BR /&gt;
&lt;BR /&gt;
    Public Function isFileInUse(ByVal sFile As String) As Boolean&lt;BR /&gt;
        If System.IO.File.Exists(sFile) Then&lt;BR /&gt;
            Try&lt;BR /&gt;
                Dim F As Short = FreeFile()&lt;BR /&gt;
                FileOpen(F, sFile, OpenMode.Binary, OpenAccess.ReadWrite, &lt;BR /&gt;
OpenShare.LockReadWrite)&lt;BR /&gt;
                FileClose(F)&lt;BR /&gt;
            Catch&lt;BR /&gt;
                Return True&lt;BR /&gt;
            End Try&lt;BR /&gt;
        End If&lt;BR /&gt;
    End Function&lt;BR /&gt;
&lt;BR /&gt;
    Function CheckNotepad(ByVal textFile As String) As Boolean&lt;BR /&gt;
        Dim ProcessList As System.Diagnostics.Process()&lt;BR /&gt;
        Dim Proc As System.Diagnostics.Process&lt;BR /&gt;
&lt;BR /&gt;
        Dim rtnValue As Boolean = False&lt;BR /&gt;
        ProcessList = System.Diagnostics.Process.GetProcesses()&lt;BR /&gt;
        Try&lt;BR /&gt;
            For Each Proc In ProcessList&lt;BR /&gt;
                If Proc.ProcessName.ToUpper = "NOTEPAD" Then&lt;BR /&gt;
                    If Proc.MainWindowTitle.Substring(0, &lt;BR /&gt;
textFile.Length).ToUpper = textFile.ToUpper Then&lt;BR /&gt;
                        rtnValue = True&lt;BR /&gt;
                        Exit For&lt;BR /&gt;
                    End If&lt;BR /&gt;
                End If&lt;BR /&gt;
            Next&lt;BR /&gt;
        Catch ex As Exception&lt;BR /&gt;
        End Try&lt;BR /&gt;
        Return rtnValue&lt;BR /&gt;
    End Function&lt;BR /&gt;
&lt;BR /&gt;
End Class&lt;BR /&gt;
{code}&lt;/ARCTICAD&gt;</description>
      <pubDate>Sun, 31 Jan 2010 15:41:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/detecting-a-file-in-use/m-p/2624728#M67293</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-01-31T15:41:11Z</dc:date>
    </item>
    <item>
      <title>Re: detecting a file in use</title>
      <link>https://forums.autodesk.com/t5/net-forum/detecting-a-file-in-use/m-p/2624729#M67294</link>
      <description>Well, opening file for writing may not be sufficient to detect if a file has &lt;BR /&gt;
been already in use by other application (such as NotePad), even though it &lt;BR /&gt;
works in most cases.&lt;BR /&gt;
&lt;BR /&gt;
Some applications allow file it opens being shared by either open the file &lt;BR /&gt;
in shared mode explicitly, or implicitly (NotePad).&lt;BR /&gt;
&lt;BR /&gt;
So, in order to achieve your goal, you also need to pass the third parameter &lt;BR /&gt;
FileShare.None enumeration value to various file/stream open method:&lt;BR /&gt;
&lt;BR /&gt;
file = New FileStream("c:\test.txt", FileMode.Append, FileAccess.Write, &lt;BR /&gt;
FileShare.None)&lt;BR /&gt;
&lt;BR /&gt;
In this case, if the file/Stream cannot be opened exclusively/not shared, &lt;BR /&gt;
the file is used by other app.&lt;BR /&gt;
&lt;BR /&gt;
The approach in the other post (find NotePad process) is only useful if &lt;BR /&gt;
NotePad is the only app that could open the file of your interested in. But &lt;BR /&gt;
it is still unnecessarily complicated and not to the point at the issue in &lt;BR /&gt;
hand.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
"Ray S Whitmore" &lt;RAY&gt; wrote in message &lt;BR /&gt;
news:6327623@discussion.autodesk.com...&lt;BR /&gt;
This is getting interesting (and confusing). Tried the following code:&lt;BR /&gt;
&lt;BR /&gt;
Try&lt;BR /&gt;
   Dim file As FileStream&lt;BR /&gt;
   file = New FileStream("c:\test.txt", FileMode.Append, FileAccess.Write)&lt;BR /&gt;
   FileClose()&lt;BR /&gt;
   MsgBox("file can be deleted")&lt;BR /&gt;
Catch&lt;BR /&gt;
   MsgBox("file cannot be deleted")&lt;BR /&gt;
End Try&lt;BR /&gt;
&lt;BR /&gt;
It indicated that the file could be deleted whether the file was currently&lt;BR /&gt;
open in Notepad or not.&lt;BR /&gt;
&lt;BR /&gt;
Opened the file in Excel and then ran the above code - works as desired.&lt;BR /&gt;
&lt;BR /&gt;
Opened file in Notepad and then tried to open it at the same time in Excel.&lt;BR /&gt;
Got a message that the file is in use by another user.&lt;BR /&gt;
&lt;BR /&gt;
So Excel can detect that the file is open by another user but my routine&lt;BR /&gt;
does not. Do you know of another way to test the file?&lt;BR /&gt;
&lt;BR /&gt;
"Tony Tanzillo" &lt;TONY.TANZILLO&gt; wrote in message&lt;BR /&gt;
news:6327450@discussion.autodesk.com...&lt;BR /&gt;
You're confusing two different things.&lt;BR /&gt;
&lt;BR /&gt;
The readonly attribute of a file means the file is read-only&lt;BR /&gt;
and can't be written to.&lt;BR /&gt;
&lt;BR /&gt;
You can open any file in notepad, read-only or not, but&lt;BR /&gt;
you can't save changes to it in notepad if it's read-only.&lt;BR /&gt;
&lt;BR /&gt;
Notepad doesn't put any kind of lock on a file when it&lt;BR /&gt;
opens it, it just reads the file and displays its contents,&lt;BR /&gt;
and doesn't access the file again until you try to save.&lt;BR /&gt;
&lt;BR /&gt;
The standard test for detecting if a file is writeable is&lt;BR /&gt;
to open it for write, using "append" mode, which will&lt;BR /&gt;
not erase the existing file's contents if it succeeds,&lt;BR /&gt;
and then immediately close the file if the open succeeds&lt;BR /&gt;
(which means the file is writeable).&lt;BR /&gt;
&lt;BR /&gt;
I don't know what that Notepad nonsense in the other&lt;BR /&gt;
post is about, but you really should avoid cheesy hacks&lt;BR /&gt;
like that, like the plauge.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD&lt;BR /&gt;
Supporting AutoCAD 2000 through 2010&lt;BR /&gt;
&lt;BR /&gt;
http://www.acadxtabs.com&lt;BR /&gt;
&lt;BR /&gt;
Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");&lt;BR /&gt;
&lt;BR /&gt;
"Ray S Whitmore" &lt;RAY&gt; wrote in message&lt;BR /&gt;
news:6327347@discussion.autodesk.com...&lt;BR /&gt;
I'm trying to delete an existing file and need to detect whether it is&lt;BR /&gt;
currently open by another program. The following is a snippet of code I&lt;BR /&gt;
tested it with:&lt;BR /&gt;
Public Sub TestReadOnly&lt;BR /&gt;
&lt;BR /&gt;
   Dim CheckFile As New IO.FileInfo("c:\test.txt")&lt;BR /&gt;
&lt;BR /&gt;
   MsgBox("IsReadOnly = " &amp;amp; CheckFile.IsReadOnly)&lt;BR /&gt;
&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
I open the test.txt file in Notepad and then run the above in AutoCAD. The&lt;BR /&gt;
Msgbox says IsReadOnly = false. I would expect it to be true.&lt;BR /&gt;
&lt;BR /&gt;
I'm stumped.&lt;/RAY&gt;&lt;/TONY.TANZILLO&gt;&lt;/RAY&gt;</description>
      <pubDate>Sun, 31 Jan 2010 19:41:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/detecting-a-file-in-use/m-p/2624729#M67294</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-01-31T19:41:06Z</dc:date>
    </item>
    <item>
      <title>Re: detecting a file in use</title>
      <link>https://forums.autodesk.com/t5/net-forum/detecting-a-file-in-use/m-p/2624730#M67295</link>
      <description>{quote}&lt;BR /&gt;
&lt;BR /&gt;
Opened file in Notepad and then tried to open it at the same time in Excel.&lt;BR /&gt;
Got a message that the file is in use by another user.&lt;BR /&gt;
&lt;BR /&gt;
{quote}&lt;BR /&gt;
&lt;BR /&gt;
It doesn't work that way here.  I open a file with notepad, then&lt;BR /&gt;
opened the same file with Excel and the file opens in both.&lt;BR /&gt;
&lt;BR /&gt;
Regardless of that, none of this makes any sense.&lt;BR /&gt;
&lt;BR /&gt;
If you are going to delete the file, then you can try to delete it,&lt;BR /&gt;
and if for any reason you can't, there will be an exception thrown&lt;BR /&gt;
that you can catch, so what's the problem?&lt;BR /&gt;
&lt;BR /&gt;
If you only want to know if a file can be deleted, you can use the&lt;BR /&gt;
File.Move() method to rename the file, and catch the exception&lt;BR /&gt;
that's thrown if the file can't be deleted, and if there is no exception&lt;BR /&gt;
you can rename the file back to the original name, and then you&lt;BR /&gt;
know if the file can be deleted without actually doing it.&lt;BR /&gt;
&lt;BR /&gt;
Whether a file is 'in use' or not depends on whether the application&lt;BR /&gt;
that opens the file specifies that the file can't be accessed at all, or&lt;BR /&gt;
accessed for reading only.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD&lt;BR /&gt;
Supporting AutoCAD 2000 through 2010&lt;BR /&gt;
&lt;BR /&gt;
http://www.acadxtabs.com&lt;BR /&gt;
&lt;BR /&gt;
Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");&lt;BR /&gt;
&lt;BR /&gt;
"Ray S Whitmore" &lt;RAY&gt; wrote in message&lt;BR /&gt;
news:6327623@discussion.autodesk.com...&lt;BR /&gt;
This is getting interesting (and confusing). Tried the following code:&lt;BR /&gt;
&lt;BR /&gt;
Try&lt;BR /&gt;
   Dim file As FileStream&lt;BR /&gt;
   file = New FileStream("c:\test.txt", FileMode.Append, FileAccess.Write)&lt;BR /&gt;
   FileClose()&lt;BR /&gt;
   MsgBox("file can be deleted")&lt;BR /&gt;
Catch&lt;BR /&gt;
   MsgBox("file cannot be deleted")&lt;BR /&gt;
End Try&lt;BR /&gt;
&lt;BR /&gt;
It indicated that the file could be deleted whether the file was currently&lt;BR /&gt;
open in Notepad or not.&lt;BR /&gt;
&lt;BR /&gt;
Opened the file in Excel and then ran the above code - works as desired.&lt;BR /&gt;
&lt;BR /&gt;
Opened file in Notepad and then tried to open it at the same time in Excel.&lt;BR /&gt;
Got a message that the file is in use by another user.&lt;BR /&gt;
&lt;BR /&gt;
So Excel can detect that the file is open by another user but my routine&lt;BR /&gt;
does not. Do you know of another way to test the file?&lt;BR /&gt;
&lt;BR /&gt;
"Tony Tanzillo" &lt;TONY.TANZILLO&gt; wrote in message&lt;BR /&gt;
news:6327450@discussion.autodesk.com...&lt;BR /&gt;
You're confusing two different things.&lt;BR /&gt;
&lt;BR /&gt;
The readonly attribute of a file means the file is read-only&lt;BR /&gt;
and can't be written to.&lt;BR /&gt;
&lt;BR /&gt;
You can open any file in notepad, read-only or not, but&lt;BR /&gt;
you can't save changes to it in notepad if it's read-only.&lt;BR /&gt;
&lt;BR /&gt;
Notepad doesn't put any kind of lock on a file when it&lt;BR /&gt;
opens it, it just reads the file and displays its contents,&lt;BR /&gt;
and doesn't access the file again until you try to save.&lt;BR /&gt;
&lt;BR /&gt;
The standard test for detecting if a file is writeable is&lt;BR /&gt;
to open it for write, using "append" mode, which will&lt;BR /&gt;
not erase the existing file's contents if it succeeds,&lt;BR /&gt;
and then immediately close the file if the open succeeds&lt;BR /&gt;
(which means the file is writeable).&lt;BR /&gt;
&lt;BR /&gt;
I don't know what that Notepad nonsense in the other&lt;BR /&gt;
post is about, but you really should avoid cheesy hacks&lt;BR /&gt;
like that, like the plauge.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD&lt;BR /&gt;
Supporting AutoCAD 2000 through 2010&lt;BR /&gt;
&lt;BR /&gt;
http://www.acadxtabs.com&lt;BR /&gt;
&lt;BR /&gt;
Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");&lt;BR /&gt;
&lt;BR /&gt;
"Ray S Whitmore" &lt;RAY&gt; wrote in message&lt;BR /&gt;
news:6327347@discussion.autodesk.com...&lt;BR /&gt;
I'm trying to delete an existing file and need to detect whether it is&lt;BR /&gt;
currently open by another program. The following is a snippet of code I&lt;BR /&gt;
tested it with:&lt;BR /&gt;
Public Sub TestReadOnly&lt;BR /&gt;
&lt;BR /&gt;
   Dim CheckFile As New IO.FileInfo("c:\test.txt")&lt;BR /&gt;
&lt;BR /&gt;
   MsgBox("IsReadOnly = " &amp;amp; CheckFile.IsReadOnly)&lt;BR /&gt;
&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
I open the test.txt file in Notepad and then run the above in AutoCAD. The&lt;BR /&gt;
Msgbox says IsReadOnly = false. I would expect it to be true.&lt;BR /&gt;
&lt;BR /&gt;
I'm stumped.&lt;/RAY&gt;&lt;/TONY.TANZILLO&gt;&lt;/RAY&gt;</description>
      <pubDate>Mon, 01 Feb 2010 01:37:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/detecting-a-file-in-use/m-p/2624730#M67295</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-02-01T01:37:14Z</dc:date>
    </item>
    <item>
      <title>Re: detecting a file in use</title>
      <link>https://forums.autodesk.com/t5/net-forum/detecting-a-file-in-use/m-p/2624731#M67296</link>
      <description>This is a good thought but, again, since Notepad does not put a lock on a &lt;BR /&gt;
file it opens, your procedure does not detect a file that has been opened by &lt;BR /&gt;
Notepad.&lt;BR /&gt;
&lt;BR /&gt;
"Norman Yuan" &lt;FAKENAME&gt; wrote in message &lt;BR /&gt;
news:6327664@discussion.autodesk.com...&lt;BR /&gt;
Well, opening file for writing may not be sufficient to detect if a file has&lt;BR /&gt;
been already in use by other application (such as NotePad), even though it&lt;BR /&gt;
works in most cases.&lt;BR /&gt;
&lt;BR /&gt;
Some applications allow file it opens being shared by either open the file&lt;BR /&gt;
in shared mode explicitly, or implicitly (NotePad).&lt;BR /&gt;
&lt;BR /&gt;
So, in order to achieve your goal, you also need to pass the third parameter&lt;BR /&gt;
FileShare.None enumeration value to various file/stream open method:&lt;BR /&gt;
&lt;BR /&gt;
file = New FileStream("c:\test.txt", FileMode.Append, FileAccess.Write,&lt;BR /&gt;
FileShare.None)&lt;BR /&gt;
&lt;BR /&gt;
In this case, if the file/Stream cannot be opened exclusively/not shared,&lt;BR /&gt;
the file is used by other app.&lt;BR /&gt;
&lt;BR /&gt;
The approach in the other post (find NotePad process) is only useful if&lt;BR /&gt;
NotePad is the only app that could open the file of your interested in. But&lt;BR /&gt;
it is still unnecessarily complicated and not to the point at the issue in&lt;BR /&gt;
hand.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
"Ray S Whitmore" &lt;RAY&gt; wrote in message&lt;BR /&gt;
news:6327623@discussion.autodesk.com...&lt;BR /&gt;
This is getting interesting (and confusing). Tried the following code:&lt;BR /&gt;
&lt;BR /&gt;
Try&lt;BR /&gt;
   Dim file As FileStream&lt;BR /&gt;
   file = New FileStream("c:\test.txt", FileMode.Append, FileAccess.Write)&lt;BR /&gt;
   FileClose()&lt;BR /&gt;
   MsgBox("file can be deleted")&lt;BR /&gt;
Catch&lt;BR /&gt;
   MsgBox("file cannot be deleted")&lt;BR /&gt;
End Try&lt;BR /&gt;
&lt;BR /&gt;
It indicated that the file could be deleted whether the file was currently&lt;BR /&gt;
open in Notepad or not.&lt;BR /&gt;
&lt;BR /&gt;
Opened the file in Excel and then ran the above code - works as desired.&lt;BR /&gt;
&lt;BR /&gt;
Opened file in Notepad and then tried to open it at the same time in Excel.&lt;BR /&gt;
Got a message that the file is in use by another user.&lt;BR /&gt;
&lt;BR /&gt;
So Excel can detect that the file is open by another user but my routine&lt;BR /&gt;
does not. Do you know of another way to test the file?&lt;BR /&gt;
&lt;BR /&gt;
"Tony Tanzillo" &lt;TONY.TANZILLO&gt; wrote in message&lt;BR /&gt;
news:6327450@discussion.autodesk.com...&lt;BR /&gt;
You're confusing two different things.&lt;BR /&gt;
&lt;BR /&gt;
The readonly attribute of a file means the file is read-only&lt;BR /&gt;
and can't be written to.&lt;BR /&gt;
&lt;BR /&gt;
You can open any file in notepad, read-only or not, but&lt;BR /&gt;
you can't save changes to it in notepad if it's read-only.&lt;BR /&gt;
&lt;BR /&gt;
Notepad doesn't put any kind of lock on a file when it&lt;BR /&gt;
opens it, it just reads the file and displays its contents,&lt;BR /&gt;
and doesn't access the file again until you try to save.&lt;BR /&gt;
&lt;BR /&gt;
The standard test for detecting if a file is writeable is&lt;BR /&gt;
to open it for write, using "append" mode, which will&lt;BR /&gt;
not erase the existing file's contents if it succeeds,&lt;BR /&gt;
and then immediately close the file if the open succeeds&lt;BR /&gt;
(which means the file is writeable).&lt;BR /&gt;
&lt;BR /&gt;
I don't know what that Notepad nonsense in the other&lt;BR /&gt;
post is about, but you really should avoid cheesy hacks&lt;BR /&gt;
like that, like the plauge.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD&lt;BR /&gt;
Supporting AutoCAD 2000 through 2010&lt;BR /&gt;
&lt;BR /&gt;
http://www.acadxtabs.com&lt;BR /&gt;
&lt;BR /&gt;
Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");&lt;BR /&gt;
&lt;BR /&gt;
"Ray S Whitmore" &lt;RAY&gt; wrote in message&lt;BR /&gt;
news:6327347@discussion.autodesk.com...&lt;BR /&gt;
I'm trying to delete an existing file and need to detect whether it is&lt;BR /&gt;
currently open by another program. The following is a snippet of code I&lt;BR /&gt;
tested it with:&lt;BR /&gt;
Public Sub TestReadOnly&lt;BR /&gt;
&lt;BR /&gt;
   Dim CheckFile As New IO.FileInfo("c:\test.txt")&lt;BR /&gt;
&lt;BR /&gt;
   MsgBox("IsReadOnly = " &amp;amp; CheckFile.IsReadOnly)&lt;BR /&gt;
&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
I open the test.txt file in Notepad and then run the above in AutoCAD. The&lt;BR /&gt;
Msgbox says IsReadOnly = false. I would expect it to be true.&lt;BR /&gt;
&lt;BR /&gt;
I'm stumped.&lt;/RAY&gt;&lt;/TONY.TANZILLO&gt;&lt;/RAY&gt;&lt;/FAKENAME&gt;</description>
      <pubDate>Mon, 01 Feb 2010 17:39:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/detecting-a-file-in-use/m-p/2624731#M67296</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-02-01T17:39:40Z</dc:date>
    </item>
    <item>
      <title>Re: detecting a file in use</title>
      <link>https://forums.autodesk.com/t5/net-forum/detecting-a-file-in-use/m-p/2624732#M67297</link>
      <description>I guess it all boils down to philosophy. I don't like a procedure that may &lt;BR /&gt;
cause confusion for any user. If we simply delete the file in question, then &lt;BR /&gt;
the Notepad user later gets an error message saying that the file exists &lt;BR /&gt;
when he tries to save. So he is either confused and gets frustrated, maybe &lt;BR /&gt;
checks the documentation (if I remembered to documentt this condition), &lt;BR /&gt;
blames the "stupid"  program, or calls his dealer for support (me).&lt;BR /&gt;
&lt;BR /&gt;
Wish Microsoft would following its own guidelines on all its applications.&lt;BR /&gt;
&lt;BR /&gt;
"Tony Tanzillo" &lt;TONY.TANZILLO&gt; wrote in message &lt;BR /&gt;
news:6327719@discussion.autodesk.com...&lt;BR /&gt;
{quote}&lt;BR /&gt;
&lt;BR /&gt;
Opened file in Notepad and then tried to open it at the same time in Excel.&lt;BR /&gt;
Got a message that the file is in use by another user.&lt;BR /&gt;
&lt;BR /&gt;
{quote}&lt;BR /&gt;
&lt;BR /&gt;
It doesn't work that way here.  I open a file with notepad, then&lt;BR /&gt;
opened the same file with Excel and the file opens in both.&lt;BR /&gt;
&lt;BR /&gt;
Regardless of that, none of this makes any sense.&lt;BR /&gt;
&lt;BR /&gt;
If you are going to delete the file, then you can try to delete it,&lt;BR /&gt;
and if for any reason you can't, there will be an exception thrown&lt;BR /&gt;
that you can catch, so what's the problem?&lt;BR /&gt;
&lt;BR /&gt;
If you only want to know if a file can be deleted, you can use the&lt;BR /&gt;
File.Move() method to rename the file, and catch the exception&lt;BR /&gt;
that's thrown if the file can't be deleted, and if there is no exception&lt;BR /&gt;
you can rename the file back to the original name, and then you&lt;BR /&gt;
know if the file can be deleted without actually doing it.&lt;BR /&gt;
&lt;BR /&gt;
Whether a file is 'in use' or not depends on whether the application&lt;BR /&gt;
that opens the file specifies that the file can't be accessed at all, or&lt;BR /&gt;
accessed for reading only.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD&lt;BR /&gt;
Supporting AutoCAD 2000 through 2010&lt;BR /&gt;
&lt;BR /&gt;
http://www.acadxtabs.com&lt;BR /&gt;
&lt;BR /&gt;
Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");&lt;BR /&gt;
&lt;BR /&gt;
"Ray S Whitmore" &lt;RAY&gt; wrote in message&lt;BR /&gt;
news:6327623@discussion.autodesk.com...&lt;BR /&gt;
This is getting interesting (and confusing). Tried the following code:&lt;BR /&gt;
&lt;BR /&gt;
Try&lt;BR /&gt;
   Dim file As FileStream&lt;BR /&gt;
   file = New FileStream("c:\test.txt", FileMode.Append, FileAccess.Write)&lt;BR /&gt;
   FileClose()&lt;BR /&gt;
   MsgBox("file can be deleted")&lt;BR /&gt;
Catch&lt;BR /&gt;
   MsgBox("file cannot be deleted")&lt;BR /&gt;
End Try&lt;BR /&gt;
&lt;BR /&gt;
It indicated that the file could be deleted whether the file was currently&lt;BR /&gt;
open in Notepad or not.&lt;BR /&gt;
&lt;BR /&gt;
Opened the file in Excel and then ran the above code - works as desired.&lt;BR /&gt;
&lt;BR /&gt;
Opened file in Notepad and then tried to open it at the same time in Excel.&lt;BR /&gt;
Got a message that the file is in use by another user.&lt;BR /&gt;
&lt;BR /&gt;
So Excel can detect that the file is open by another user but my routine&lt;BR /&gt;
does not. Do you know of another way to test the file?&lt;BR /&gt;
&lt;BR /&gt;
"Tony Tanzillo" &lt;TONY.TANZILLO&gt; wrote in message&lt;BR /&gt;
news:6327450@discussion.autodesk.com...&lt;BR /&gt;
You're confusing two different things.&lt;BR /&gt;
&lt;BR /&gt;
The readonly attribute of a file means the file is read-only&lt;BR /&gt;
and can't be written to.&lt;BR /&gt;
&lt;BR /&gt;
You can open any file in notepad, read-only or not, but&lt;BR /&gt;
you can't save changes to it in notepad if it's read-only.&lt;BR /&gt;
&lt;BR /&gt;
Notepad doesn't put any kind of lock on a file when it&lt;BR /&gt;
opens it, it just reads the file and displays its contents,&lt;BR /&gt;
and doesn't access the file again until you try to save.&lt;BR /&gt;
&lt;BR /&gt;
The standard test for detecting if a file is writeable is&lt;BR /&gt;
to open it for write, using "append" mode, which will&lt;BR /&gt;
not erase the existing file's contents if it succeeds,&lt;BR /&gt;
and then immediately close the file if the open succeeds&lt;BR /&gt;
(which means the file is writeable).&lt;BR /&gt;
&lt;BR /&gt;
I don't know what that Notepad nonsense in the other&lt;BR /&gt;
post is about, but you really should avoid cheesy hacks&lt;BR /&gt;
like that, like the plauge.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD&lt;BR /&gt;
Supporting AutoCAD 2000 through 2010&lt;BR /&gt;
&lt;BR /&gt;
http://www.acadxtabs.com&lt;BR /&gt;
&lt;BR /&gt;
Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");&lt;BR /&gt;
&lt;BR /&gt;
"Ray S Whitmore" &lt;RAY&gt; wrote in message&lt;BR /&gt;
news:6327347@discussion.autodesk.com...&lt;BR /&gt;
I'm trying to delete an existing file and need to detect whether it is&lt;BR /&gt;
currently open by another program. The following is a snippet of code I&lt;BR /&gt;
tested it with:&lt;BR /&gt;
Public Sub TestReadOnly&lt;BR /&gt;
&lt;BR /&gt;
   Dim CheckFile As New IO.FileInfo("c:\test.txt")&lt;BR /&gt;
&lt;BR /&gt;
   MsgBox("IsReadOnly = " &amp;amp; CheckFile.IsReadOnly)&lt;BR /&gt;
&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
I open the test.txt file in Notepad and then run the above in AutoCAD. The&lt;BR /&gt;
Msgbox says IsReadOnly = false. I would expect it to be true.&lt;BR /&gt;
&lt;BR /&gt;
I'm stumped.&lt;/RAY&gt;&lt;/TONY.TANZILLO&gt;&lt;/RAY&gt;&lt;/TONY.TANZILLO&gt;</description>
      <pubDate>Mon, 01 Feb 2010 17:47:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/detecting-a-file-in-use/m-p/2624732#M67297</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-02-01T17:47:18Z</dc:date>
    </item>
  </channel>
</rss>

