示例#1
0
        private string SanitizePath(string FilePath)
        {
            string Root     = Path.GetPathRoot(FilePath);
            string FileName = Path.GetFileName(FilePath);

            if (Path.IsPathRooted(FilePath))
            {
                FilePath = FilePath.Replace(Root, String.Empty);
            }
            FilePath = FilePath.Replace(":", String.Empty);
            FilePath = FilePath.Replace(FileName, String.Empty);
            foreach (char Invalid in Path.GetInvalidPathChars())
            {
                FilePath = FilePath.Replace(Invalid.ToString(), String.Empty);
            }
            foreach (char Invalid in Path.GetInvalidFileNameChars())
            {
                FileName = FileName.Replace(Invalid.ToString(), String.Empty);
            }
            FilePath = Path.Combine(Root, FilePath, FileName);

            return(FilePath);
        }