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. Download first and last 1000 kb of a file?

Download first and last 1000 kb of a file?

Scheduled Pinned Locked Moved C#
csharptutorialquestion
4 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.
  • J Offline
    J Offline
    jafingi
    wrote on last edited by
    #1

    Hi Can anyone tell me how I can download the first 1000 kb and last 1000 kb of a file in C#? When downloaded, the file should just be deleted. Have no clue on how to do this. Thanks in advance

    E 1 Reply Last reply
    0
    • J jafingi

      Hi Can anyone tell me how I can download the first 1000 kb and last 1000 kb of a file in C#? When downloaded, the file should just be deleted. Have no clue on how to do this. Thanks in advance

      E Offline
      E Offline
      Eduard Keilholz
      wrote on last edited by
      #2

      You can open the file using a stream and read the first and last 1000 Kb of the file. You can store that data in a seperate file.

      .: I love it when a plan comes together :. http://www.zonderpunt.nl

      J 1 Reply Last reply
      0
      • E Eduard Keilholz

        You can open the file using a stream and read the first and last 1000 Kb of the file. You can store that data in a seperate file.

        .: I love it when a plan comes together :. http://www.zonderpunt.nl

        J Offline
        J Offline
        jafingi
        wrote on last edited by
        #3

        I don't need to store the data - actually, the downloaded bytes should just be deleted afterwards. Thought about doing something like this: reader.ReadBytes(1000); reader.Position = (file.Length - 1000); reader.ReadBytes(1000); Would that work? And what is the file is smaller than 1000kb?

        E 1 Reply Last reply
        0
        • J jafingi

          I don't need to store the data - actually, the downloaded bytes should just be deleted afterwards. Thought about doing something like this: reader.ReadBytes(1000); reader.Position = (file.Length - 1000); reader.ReadBytes(1000); Would that work? And what is the file is smaller than 1000kb?

          E Offline
          E Offline
          Eduard Keilholz
          wrote on last edited by
          #4

          If the stream is seekable, you're pretty close. I think, if the stream is smaller than 2000 Kb you should read the entire file? Else you would copy duplicate data and (if the file is less than 1000 Kb) cause an exception.

          .: I love it when a plan comes together :. http://www.zonderpunt.nl

          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