Guest User

Untitled

a guest
Jan 20th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. bool IsValidFilename(string testName)
  2. {
  3. Regex containsABadCharacter = new Regex("[" + Regex.Escape(System.IO.Path.InvalidPathChars) + "]");
  4. if (containsABadCharacter.IsMatch(testName) { return false; };
  5.  
  6. return true;
  7. }
  8.  
  9. var file = "myfile.txt";
  10. var fileExists = System.IO.File.Exists(file);
  11.  
  12. var file = "mybadfile<\/.txt";
  13. var invalidFileChars = System.IO.Path.GetInvalidFileNameChars();
  14. var isInvalidFilename = invalidFileChars.Any(s => file.Contains(s));
Add Comment
Please, Sign In to add comment