Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. fileinfo to string??

fileinfo to string??

Scheduled Pinned Locked Moved Visual Basic
question
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Silver Grey
    wrote on last edited by
    #1

    I'm getting a file from a listbox that is fileinfo. I'm going to do some reading and writing based on the data in the selected file. I can only find examples of streamreader that use file name as a string. How do I convert the fileinfo to string? Thanks

    silver-gray

    C G M 4 Replies Last reply
    0
    • S Silver Grey

      I'm getting a file from a listbox that is fileinfo. I'm going to do some reading and writing based on the data in the selected file. I can only find examples of streamreader that use file name as a string. How do I convert the fileinfo to string? Thanks

      silver-gray

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Every .NET class has a tostring method. What do you mean by FileInfo ? Surely there's a sring there, what's the listbox showing ?

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

      1 Reply Last reply
      0
      • S Silver Grey

        I'm getting a file from a listbox that is fileinfo. I'm going to do some reading and writing based on the data in the selected file. I can only find examples of streamreader that use file name as a string. How do I convert the fileinfo to string? Thanks

        silver-gray

        G Offline
        G Offline
        Gideon Engelberth
        wrote on last edited by
        #3

        You should look into the FileInfo.OpenRead and FileInfo.OpenWrite methods. This will return a FileStream that you can use in the constructor of a StreamReader. Example Imports System.IO Dim fi As FileInfo 'get object from list box Using fs As FileStream = fi.OpenRead() 'use fi.OpenWrite() for a writeable stream Using sr As New StreamReader(fs) 'read or write here End Using End Using

        1 Reply Last reply
        0
        • S Silver Grey

          I'm getting a file from a listbox that is fileinfo. I'm going to do some reading and writing based on the data in the selected file. I can only find examples of streamreader that use file name as a string. How do I convert the fileinfo to string? Thanks

          silver-gray

          M Offline
          M Offline
          manish24
          wrote on last edited by
          #4

          Try it out. It will read a file and will put the contents of file into a string. Dim reader As StreamReader = File.OpenText("c:\myfile.txt") Dim line As String = reader.ReadToEnd Manish

          1 Reply Last reply
          0
          • S Silver Grey

            I'm getting a file from a listbox that is fileinfo. I'm going to do some reading and writing based on the data in the selected file. I can only find examples of streamreader that use file name as a string. How do I convert the fileinfo to string? Thanks

            silver-gray

            M Offline
            M Offline
            manish24
            wrote on last edited by
            #5

            Try it out. This code will read a file and will put file's contents into a string Dim reader As StreamReader = File.OpenText("c:\myfile.txt") Dim line As String = reader.ReadToEnd Manish

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups