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