Question read a text file from a USB with unspecified drive letter?

jnvu_16

New member
Joined
Jun 18, 2012
Messages
2
Programming Experience
Beginner
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,

VB.NET:
<%@ Import NameSpace="System.IO" %>[/FONT][/COLOR]

[COLOR=#333333][FONT=arial]<%[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]For Each d As System.IO.DriveInfo In My.Computer.FileSystem.Drives[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]If d.DriveType = DriveType.Removable Then[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]Dim test As String = File.ReadAllText(& ":\\sample.txt")[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]Response.Write(test)[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]End If[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]Next[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]%>[/FONT][/COLOR][COLOR=#333333][FONT=arial]
 
Under what circumstances would you have a drive with no letter assigned to it? Windows' HAL will mount it and assign it a letter automatically on insertion.
 
Back
Top