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. Get Stream File Location

Get Stream File Location

Scheduled Pinned Locked Moved C#
question
2 Posts 2 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
    sabrown100
    wrote on last edited by
    #1

    How can I get the location of the file being streamed from the "System.IO.Stream" class?

    J 1 Reply Last reply
    0
    • S sabrown100

      How can I get the location of the file being streamed from the "System.IO.Stream" class?

      J Offline
      J Offline
      J Dunlap
      wrote on last edited by
      #2

      The Stream class is an abstract base class, and derived classes may not represent a file (for example, MemoryStream represents an in-memory byte stream). In .NET, the FileStream class is usually used to deal with file I/O, so if the stream you're dealing with is based on a file, the Stream will likely be a FileStream instance. You can use FileStream.Name to get the original filename - for example:

      string GetStreamFilename(Stream stream)
      {
      FileStream fs=stream as FileStream;
      //if it's a FileStream return its name
      if(fs!=null)
      return fs.Name;
      //otherwise, it's probably not file-based
      return null;
      }

      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