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. C#
  4. Convert a file to stream

Convert a file to stream

Scheduled Pinned Locked Moved C#
tutorialquestion
4 Posts 3 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.
  • Q Offline
    Q Offline
    QzRz
    wrote on last edited by
    #1

    Hello I want convert a file into a stream. I do it like this: FileInfo fl = new FileInfo(@"C:\test.wav"); Stream sm = fl.Open(FileMode.Open); But I do not think this is the best way to do it! Can someone tell me if this is a good way, or maybe tell me a better way of how to do this? Thanks QzRz

    D S 2 Replies Last reply
    0
    • Q QzRz

      Hello I want convert a file into a stream. I do it like this: FileInfo fl = new FileInfo(@"C:\test.wav"); Stream sm = fl.Open(FileMode.Open); But I do not think this is the best way to do it! Can someone tell me if this is a good way, or maybe tell me a better way of how to do this? Thanks QzRz

      D Offline
      D Offline
      DigitalKing
      wrote on last edited by
      #2

      This is a good way, but the FileInfo object is not necessary (unless you are using it somewhere else). Try this:

      Stream sm = new FileStream(@"C:\test.wav", FileMode.Open);

      Hope this helps, DigitalKing

      Q 1 Reply Last reply
      0
      • D DigitalKing

        This is a good way, but the FileInfo object is not necessary (unless you are using it somewhere else). Try this:

        Stream sm = new FileStream(@"C:\test.wav", FileMode.Open);

        Hope this helps, DigitalKing

        Q Offline
        Q Offline
        QzRz
        wrote on last edited by
        #3

        Thanks for the fast reply :) I do not need the FileInfo, so the answer you gave me is very good. Thanks

        1 Reply Last reply
        0
        • Q QzRz

          Hello I want convert a file into a stream. I do it like this: FileInfo fl = new FileInfo(@"C:\test.wav"); Stream sm = fl.Open(FileMode.Open); But I do not think this is the best way to do it! Can someone tell me if this is a good way, or maybe tell me a better way of how to do this? Thanks QzRz

          S Offline
          S Offline
          S Senthil Kumar
          wrote on last edited by
          #4

          What DigitalKing said, but you could also use the using statement to close the stream and release resources correctly. Something like

          using (Stream s = ...)
          {

          }

          Regards Senthil _____________________________ My Blog | My Articles | My Flickr | WinMacro

          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