开发者

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("..", ".");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜