Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// Sanitizes a filename by removing invalid characters.
- /// </summary>
- /// <param name="path">The path.</param>
- /// <returns>The filename with invalid characters stripped.</returns>
- public static string SanitizeFilename(string path) {
- if(path == null || path.Length == 0) {
- return path;
- }
- string safePath = path;
- Array.ForEach(System.IO.Path.GetInvalidFileNameChars(), c => safePath = safePath.Replace(c.ToString(), string.Empty));
- return safePath;
- }
Advertisement
Add Comment
Please, Sign In to add comment