Filesystem filename escape? C#
I am allowing the user to choose any username he wants and it can be anything at all such as AC♀¿!$"Man'@ Now i need to create a directory for him. What function i use to escape the text so i dont a FS problem/exception? Use Path.GetInvalidFileNameChars or Path.GetInvalidPathChars to check for characters to remove. http://msdn.microsoft.com/en-us/library/system.io.path.getinvalidfilenamechars.aspx Whether you replace invalid characters or remove them, there's always going to be the possibility of collisions. If I were you, I'd have a separate primary key for the user (a GUID perhaps) and use