0

First the bottom line ...
If you use a loop on a Novell client Win7 containing IO.File.Exist(FileTest) looking for FileTest to disappear meaning it is time to move on, delete FileTest from another client, and you then you try to use the name FileTest represents, you will get a network error. The reason I think it has to do with Novell Client Win7, is if the share is a windows share, I do not see the problem. Also, when our clients were XP SP3 (not sure the Novell version) we did not see this. As mentioned in the comment, I tried this on a SAMBA share and did not see the issue.


Next the detail ....
It is a simple to reproduce it.

Module Module1
    Sub Main()
        Dim FileTest As String = "\\corp01\vol1\bbs\test.flg" 'corp01 is a Novell share'
        IO.File.WriteAllText(FileTest, "")
        Do While IO.File.Exists(FileTest)
            System.Threading.Thread.Sleep(100)
        Loop
    End Sub
End Module

Then from another client delete test.flg and the program ends as expected. Try running it again and when it tries to create it in the WriteAllText you will get the network error. It does not seem to matter who or how the file is created. I have tried to rem out the WriteAllText and create it from a different client, then start the program, delete it from the other client and still get the network error when trying to reference the name.


My Guess ....
I think the name is cached somehow. The only way to fix it is log off from windows. Another reason, if the WriteFileText is throwing the error and I try a different way of creating it, still have the error. For example in explorer I create a text file on the share, works ok. Then try to rename the created file to my flag name, network error. I can rename it to any other file name except for the name I use as the flag file.

penright
  • 163
  • 4
  • 12
  • I don't see how your question is tied to `IO.File.Exists(“”)` in the title. – crashmstr Oct 29 '14 at 12:47
  • I don't really see the question in the first place :D – Luaan Oct 29 '14 at 12:54
  • As far as the title, I am open to suggestion. The question is should have been :-), Any thoughts on how to accomplish this? Is it a bug in Windows, Novell? – penright Oct 29 '14 at 13:27
  • I just tried it on a smaba share and did not get the error. So it has something to do with Win7 Novell client. – penright Oct 29 '14 at 13:40
  • The Novell Client was an incredibly broken piece of software 15 years ago. Every new release was worse. A big reason why Novell is no longer in the network business, one that they once owned. Still using it today is *very* inadvisable. – Hans Passant Oct 29 '14 at 13:52
  • FYI.... Hans, I hear what you are saying, don't necessarily disagree :-), but Novell is in business today. Right now we are running the Old NLM os version. I know our network guy is switching over to suse, but not yet. Having said that, I don't know if suse will have the same issue or not. – penright Oct 29 '14 at 14:40
  • BTW, crashmstr your comment got me on the win api track, did IO.File.Exist have anything to do with the title? So how could I test? Then when I started wondering if the win api had the same issue. Since it did not, then there is something wrong with .net. I wonder if they are closing the handle? – penright Oct 29 '14 at 14:46

1 Answers1

0

For now this is the best solution I could find. Basically I tried the windows API and it did not have the issue. I tested it with all three shares (windows, Novell, SAMBA) and it seemed to work. Here is the code as an FYI. The magic is in the BRFileExist class. There may need to be a try/catch/finally of some sort for the close. I am going to try it this was in production first.

Class BRFileExist
    ' #VBIDEUtils#**************************************************
    ' * Programmer Name  : Waty Thierry
    ' * Web Site         : www.geocities.com/ResearchTriangle/6311/
    ' * E-Mail           : waty.thierry@usa.net
    ' * Date             : 28/06/99
    ' * Time             : 12:24
    ' **************************************************************
    ' * Comments         : API FileExist
    ' *
    ' *
    ' ****************************************************************'

    Private Const INVALID_HANDLE_VALUE = -1

    Private Structure FILETIME
        Dim dwLowDateTime As Long
        Dim dwHighDateTime As Long
    End Structure

    Private Structure WIN32_FIND_DATA
        Dim dwFileAttributes As Long
        Dim ftCreationTime As FILETIME
        Dim ftLastAccessTime As FILETIME
        Dim ftLastWriteTime As FILETIME
        Dim nFileSizeHigh As Long
        Dim nFileSizeLow As Long
        Dim dwReserved0 As Long
        Dim dwReserved1 As Long
        Dim cFileName As String
        Dim cAlternate As String
    End Structure

    Private Declare Function FindFirstFile Lib "kernel32" _
       Alias "FindFirstFileA" _
       (ByVal lpFileName As String, _
       ByVal lpFindFileData As WIN32_FIND_DATA) As Long

    Private Declare Function FindClose Lib "kernel32" _
       (ByVal hFindFile As Long) As Long
    Public Shared Function FileExist(ByVal pPath As String) As Boolean
        Dim WFD As New WIN32_FIND_DATA
        Dim hFile As Long = FindFirstFile(pPath, WFD)
        Dim retFileExist As Boolean = (hFile <> INVALID_HANDLE_VALUE)
        FindClose(hFile)
        Return retFileExist
    End Function
End Class
penright
  • 163
  • 4
  • 12