So I need to check a bunch of files for valid files my program can use. My file is a dll file but a specific one that only my program can use. I need to make sure if one of the files is a specific file. An extension check is not enough. How can I validate it? I need to check the file for a specific thing like a string/class. What would be the best way to do so?
Asked
Active
Viewed 44 times
0
-
Do you need to check that the file is a DLL, that it's a DLL that exposes a certain interface, or that's it's a specific file? – user3553031 Apr 23 '14 at 22:34
-
1Dynamically load the assembly and check if the needed class exists, for example try to create an instance of it, and handle accordingly. – Dmitriy Khaykin Apr 23 '14 at 22:35
-
@user3553031: I need to check if the file is a valid dll file for my program. – nexno Apr 23 '14 at 22:43
-
@Khaykin: That sounds pretty good for me, how would I perform such a check? – nexno Apr 23 '14 at 22:44
-
http://stackoverflow.com/questions/1137781/c-sharp-correct-way-to-load-assembly-find-class-and-call-run-method shows you all method needed (and also potentially necessary code to deal with unloading). – Alexei Levenkov Apr 23 '14 at 22:46
-
here is another thought calculate `MD5` of those files and store some where in the program and then during run time calculate `md5` of the dll's and compare – Bender Apr 24 '14 at 02:34