Get File Extension Substring

By wade2462 on Dec 17, 2010

Determines the file extension from a full filename.

        public static string GetFileType(string FilePath)
            List<int> PeriodPostions = new List<int>();
            int ExtensionStart = 0;
            for (int iii = 0; iii < FilePath.Length; iii++)
                if (FilePath[iii] == '.')
            ExtensionStart = PeriodPostions.Last();
            return FilePath.Substring(ExtensionStart);


Sign in to comment.
Jyncs   -  Sep 04, 2011

You could also do it with this

    public static string GetFileType(string fileName)
        string fileExt;
        string[] arrFile;
        arrFile = fileName.Split(".".ToCharArray());
        fileExt = arrFile[arrFile.Length - 1];
        return fileExt;
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.