VB.Net code to read a text file from a USB with unspecified drive letter?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: VB.Net code to read a text file from a USB with unspecified drive letter?

  1. #1
    Join Date
    Jun 2012
    Posts
    1

    Arrow 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.

  2. #2
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,845

    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.

  3. #3
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center