daily pastebin goal
80%
SHARE
TWEET

Untitled

a guest Jan 20th, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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));
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top