A few times in the last couple months I had the same task of verifying the file format by it's header: JPEG, PDF, Word, and other popular files.
I wonder if there is a library availble for C#/.Net to do that? Or is it a time to start a small project for NuGet catalogue?
It's one of the purposes of header files, to declare things, so you can include it in multiple source files and have the same declaration everywhere the header file is included.
Definition(s):Data within a file that contains identifying information about the file and possibly metadata with information about the file contents.
To import a header, use the #include, a preprocessor directive telling the compiler that it should import and process the code before compiling the rest of the code. On a typical C program, it should contain the stdio. h header file, which is the standard header file for input and output streams.
A header file looks like a normal C file, except it ends with . h instead of . c , and instead of the implementations of your functions and the other parts of a program, it holds the declarations.
For those who will find this question in the future: I have started to write the library. Once I have significant amount of different types, I'll submit it to NuGet. But at the moment the source code is available here: http://filetypedetective.codeplex.com/
The idea of the library is to be able to call isPdf()
or isZip()
on FileInfo
objects:
FileInfo file = new FileInfo("C:\Hello.pdf");
if ( file.isPdf())
Console.WriteLine("File is PDF");
etc.
Update: the finally got around to create nuget package:
Install-Package FileTypeDetective
For most file formats, you can read the magic numbers at the beginning of the file to determine the file type. This is how *nix based systems know the file type regardless of the file extension.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With