Click here to Skip to main content
15,894,460 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,
Can I read a byte from a file without opening it. It might be a little confusing as per what I want to do here. To read a byte at any position in a file regardless of the size of the file from which the byte is being read.
The file size could theoretically be 256TB, as it is the NTFS limit.
Thanks
Posted
Comments
Dave Kreskowiak 3-Sep-12 15:45pm    
Why is "not opening the file" even a requirement?? Unless you want to interpret the file system layout and follow the file map for your specified file, you have no choice but to open the file.

No.

In order to get any information from the file content, even a single byte, you have to open the file.
However, once it is open, it should be perfectly possible to address any byte in teh file directly - both the Stream.Position property and the Stream.Seek method use long values, not int, so addressing should not be a problem.

Having said that, I haven't tried it - I don't have any 1TB single files sitting around to check with! :laugh:
 
Share this answer
 
I would try to address the task on a lower level. "Opening" a file in common terms means only that I acquire a handle from a file system driver in the operating system, and in all my file operations I am using this driver and the handle I got.
But of course you can write your own tools to access the file system bypassing the driver. You can write your own driver, but also rely on some low level api functions to read the file system directly. Of course, to do this you need certain privileges, and I am not sure if you will be able to do this in managed code.

I would start from here, even if this is unmanaged:
An NTFS Parser Lib[^]

Good luck!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900