how to validate a safe filename with double (.) (.) "fileName ..pdf"
Im sarching how to create a safe filename in my webapplication I had read a lot of post around here last one How do I check if a given string is a legal / valid file name under Windows? but I can't find the solution for this example when the filena开发者_JS百科me comes in the way "fileName ..pdf" (double dot), the browser can't open the file at least IE and is a safe filename at least for windows,so how can I search for this exception and remove the double dot, what I have by now is the following example (which obviously doesn't remove the double dot:
foreach (var c in Path.GetInvalidFileNameChars()) { fileName = fileName.Replace(c, '-'); }
I would do an extra check afterwards and replace the ..
with .
:
foreach (var c in Path.GetInvalidFileNameChars())
fileName = fileName.Replace(c, '-');
fileName = fileName.Replace("..", ".");
精彩评论