Author Topic: Reading Network Drive  (Read 1004 times)

ddddd13

  • Full Member
  • ***
  • Posts: 118
    • View Profile
Reading Network Drive
« on: June 12, 2019, 03:51:56 PM »
I am trying to read a file from a network drive I have setup on another computer. I have the following code on a button.

   Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Using sr As New System.IO.StreamReader("Z:\Files\MachUpdate.txt")
            While Not sr.EndOfStream
                MachUpdate.Add(sr.ReadLine())
            End While
        End Using
        RichTextBox2.Text = MachUpdate(1)

I am quite certain something is wrong with the path Z:\Files\MachUpdate.txt because I have the same file on the computer running advanced HMI c:\Files\MachUpdate.txt and it too bombs out with system I/O file not found. Any idea what my path should be?

Thanks,
Dave

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5324
    • View Profile
    • AdvancedHMI
Re: Reading Network Drive
« Reply #1 on: June 12, 2019, 05:40:31 PM »
I never trust a mapped drive because they tend to lose connection and not reconnect. I always use the full UNC path such as:

\\servername\path\filename

ddddd13

  • Full Member
  • ***
  • Posts: 118
    • View Profile
Re: Reading Network Drive
« Reply #2 on: June 12, 2019, 07:59:34 PM »
So, I have changed the path to
  Using sr As New System.IO.StreamReader("\\DAVE-PC\Z:\Files\MachUpdate.txt")
or
 Using sr As New System.IO.StreamReader("\\(DAVE-PC)\Z:\Files\MachUpdate.txt")
I still get an alarm.
or
Using sr As New System.IO.StreamReader("(\\(DAVE-PC)\Z:\Files\MachUpdate.txt")

System not supported exception: The given path's format is not supported

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5324
    • View Profile
    • AdvancedHMI
Re: Reading Network Drive
« Reply #3 on: June 12, 2019, 08:14:34 PM »
The Z: would no longer be used unless it is a directory.

If you put the path in Windows Explorer, does it show anything?

Is your remote PC setup as a shared directory? Is the firewall turned off?

ddddd13

  • Full Member
  • ***
  • Posts: 118
    • View Profile
Re: Reading Network Drive
« Reply #4 on: June 12, 2019, 09:10:55 PM »
Archie;

This is weird as shit.

This is the way it has to be entered.

 Using sr As New System.IO.StreamReader("\\DAVE-PC\Network folder\Files\MachUpdate.txt.txt"

Without the double txt.txt it will not work

Does that make sense to you?
Dave

Noe

  • Full Member
  • ***
  • Posts: 205
    • View Profile
Re: Reading Network Drive
« Reply #5 on: June 13, 2019, 09:31:00 AM »
You have your file explorer set to hide extensions, and your file name is "MachUpdate.txt", with the extension txt. At least this is what I experienced before with similar cases.