System.IO.Path.HasExtension C# (CSharp) Méthode

HasExtension() private méthode

private HasExtension ( string path ) : bool
path string
Résultat bool
        public static bool HasExtension(string path)
        {
            if (path != null)
            {
                PathInternal.CheckInvalidPathChars(path);

                for (int i = path.Length - 1; i >= 0; i--)
                {
                    char ch = path[i];
                    if (ch == '.')
                    {
                        return i != path.Length - 1;
                    }
                    if (PathInternal.IsDirectoryOrVolumeSeparator(ch)) break;
                }
            }
            return false;
        }

Usage Example

Exemple #1
0
        private void TestBtn_Click(object sender, RoutedEventArgs e)
        {
            var ShowError = new Action <string>((errMsg) =>
                                                MessageBox.Show(errMsg, "Error",
                                                                MessageBoxButton.OK,
                                                                MessageBoxImage.Error));
            var isIncludeExtension     = IsIncludeFileTypeCB.IsChecked.GetValueOrDefault();
            var isIgnoreExtensionCheck = IsIgnoreExtensionCheck.IsChecked.GetValueOrDefault();
            var file = TestInputTxt.Text;

            var filename = isIncludeExtension ?
                           Path.GetFileName(file) :
                           Path.GetFileNameWithoutExtension(file);
            var outputName = BuildFilename(filename);

            var outputFile = outputName +
                             (isIncludeExtension ?
                              "" : Path.GetExtension(file));

            if (isIncludeExtension && !isIgnoreExtensionCheck)
            {
                //verify output file got extension
                if (!Path.HasExtension(outputFile))
                {
                    ShowError($"Resulting output filename does not have extension.\nOutput: {outputFile} for InputFile: {filename}");
                }
            }
            TestOutputTxt.Text = outputFile;
        }
All Usage Examples Of System.IO.Path::HasExtension