VB.Net code to read a text file from a USB with unspecified drive letter?
I already have a code for detecting a removable device. However, I would like to enable my program to detect that USB drive and read and print the text in that specific text file on my webpage. I also have a program code for reading and printing a text file from a USB but that program needs the drive letter to be specified. My problem is, how would I program if the drive letter is unspecified? Here is my code by the way,
<%@ Import NameSpace="System.IO" %>
For Each d As System.IO.DriveInfo In My.Computer.FileSystem.Drives
If d.DriveType = DriveType.Removable Then
Dim test As String = File.ReadAllText(& ":\\sample.txt")
My problem now is how to let the string test get the data so that I could put it on my page. I'm currently using that File.ReadAllText method but I'm open to suggestions if there would be any.
Re: VB.Net code to read a text file from a USB with unspecified drive letter?
In order to read a file then either the drive where the file is at must be the current drive or you must specify the drive letter. In general if it is not the drive you program is being ran from then you would need code to switch to that drive or specify the drive letter with the file name.