-
June 18th, 2012, 02:42 AM
#1
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,
Code:
<%@ 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")
Response.Write(test)
End If
Next
%>
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.
-
June 18th, 2012, 07:58 AM
#2
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.
Always use [code][/code] tags when posting code.
-
June 18th, 2012, 02:12 PM
#3
Re: VB.Net code to read a text file from a USB with unspecified drive letter?
try this code
Code:
For Each d As System.IO.DriveInfo In My.Computer.FileSystem.Drives
If d.DriveType = System.IO.DriveType.Removable Then
Debug.Write(d.Name)
End If
Next
it will give you the Drive letter
Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
WPF Articles : 3D Animation 1 , 2 , 3
Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|