Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool IsValidFilename(string testName)
- {
- Regex containsABadCharacter = new Regex("[" + Regex.Escape(System.IO.Path.InvalidPathChars) + "]");
- if (containsABadCharacter.IsMatch(testName) { return false; };
- return true;
- }
- var file = "myfile.txt";
- var fileExists = System.IO.File.Exists(file);
- var file = "mybadfile<\/.txt";
- var invalidFileChars = System.IO.Path.GetInvalidFileNameChars();
- var isInvalidFilename = invalidFileChars.Any(s => file.Contains(s));
Add Comment
Please, Sign In to add comment