none
StreamReader unable to find file in network location for one user/PC only out of many. RRS feed

  • Question

  • TLDR; File accessible by StreamReader for many users of program, but does not work for one user/machine. Confirmed that user has proper access to file.

    I have a program that is parsing data from a saved text file stored on a network share. Roughly 20 users/PCs are able to use this program without issue, however one user is unable to perform the task, receiving an exception:

    System.IO.FileNotFoundException: Could not find file
    '\\server\path\to\folder\file.G5246V00'.
    

    (obviously not the actual path, but the logic remains the same)

    The file exists, and this particular user can manually navigate to the share/folder and open the file through Windows Explorer, so he has proper access. Here's the relevant code block:

                Dim lines As New List(Of String)
                Dim sr As New StreamReader(strNEDir & sFilename)
                While Not sr.EndOfStream 'read each line until the end
                    Dim line As String = sr.ReadLine
                    For Each row As DataGridViewRow In Me.gridNE.Rows
                        If Mid(line, 2, 8) = Mid(row.Cells("colTask").Value.ToString, 1, 8) Then 'check if line = task
                            If Not lines.Contains(line) Then
                                lines.Add(line) 'if it does, add to list to send for display
                            End If
                        End If
                    Next
                End While
                sr.Close()

    The exception is thrown when trying to open the file with StreamReader (bolded line, I've confirmed that 'strNEDir & sFilename' is properly populated with the correct full path - those vars are populated elsewhere). This is clearly some setting pertaining specifically to this user or machine, anyone have any clue what it might be? What am I missing here?


    Wednesday, April 10, 2019 5:49 PM

All replies

  • A little restructuring of your code.

            Dim pthToFile As String
            pthToFile = IO.Path.Combine(strNEDir, sFilename)
            If IO.File.Exists(pthToFile) Then
                Dim sr As New StreamReader(pthToFile)
                'rest of your code
            Else
                'debug code here
            End If
    


    Search Documentation

    SerialPort Info

    Multics - An OS ahead of its time.

     "Those who use Application.DoEvents have no idea what it does

        and those who know what it does never use it."    former MSDN User JohnWein

    • Proposed as answer by Alex Li-MSFT Thursday, April 18, 2019 3:18 AM
    Wednesday, April 10, 2019 6:16 PM