0

I am trying to full-proof my tool, and I noticed that if you pass a database file to streamreader, it will read the file without a problem,. I would like to only be able to open text files (.txt, .xml, .json, etc.). I want the tool to exit if it tries to read an excel document or something not written in plain text.

Thanks, Nick

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
Nich42
  • 3
  • 4
  • Show what you've tried and where you're having a specific problem. – Andrew Mortimer Feb 09 '18 at 20:14
  • This was already asked here: https://stackoverflow.com/q/4744890/1732224 - it's C#, but shouldn't be a problem to change the code to VB.NET. – Fer García Feb 09 '18 at 20:16
  • 1
    Check the file extension and make sure it's correct. That doesn't stop someone from changing the file extension though. You could check the characters like suggested in the linked thread, but what if they are all integers? Any solution here is going to be fuzzy. You may spend a lot of time putting in checks for cases that will never happen. Funny thing about Excel files, they're written in XML, which is a file "type" that you want to accept. See the problem? – Jacob H Feb 09 '18 at 20:24
  • It looks like they answered my questions, unless vb has a magical alternative that doesn't translate to C#. – Nich42 Feb 09 '18 at 20:48

0 Answers0