1
static void Main(string[] args)
{
   Console.WriteLine("Enter full file name with path:");
   string strFileName = Console.ReadLine();

   string FileEx =Path.GetExtension(strFileName);
   Console.WriteLine("Your File Extension is {0}",FileEx);

}

output :

Enter full file name with path:

D:\MyFiles\TestFile.csv
Your File Extension is .csv

Here I have a problem if I saved a text file in name of TestFile.csv it shows file extension is csv but I really want actual file extension even if given a fake file name

Eg : TestFile.csv ( Type of text file ) should give .txt output TestFile.csv ( Type of csv file) should give .csv output

I think it is not possible to attain this using above Function , any valuable advice will be helpful.

Thanks in advance

C0d1ngJammer
  • 550
  • 1
  • 6
  • 21
sreeyushs
  • 11
  • 2
  • You cannot reliably do this. All files are just made up of the same thing. It is just the program that opens them that determines if it makes sense to the user. You can open a .exe file with notepad and it will display characters to you. Is this .txt or .exe by your logic?? – CathalMF Jul 30 '15 at 12:11
  • What's the difference between a text file and a csv file? – Corak Jul 30 '15 at 12:11
  • for me it works as expected, if i pass with extension of file. – DeshDeep Singh Jul 30 '15 at 12:12
  • This scenario doesn't occurs normally , occurs only when from windows features you uncheck identify extension types options. Then you will able to save a text file with .exe extension but the type name of file remains same as Text Document instead of showing it as Application. – sreeyushs Aug 02 '15 at 10:53
  • This is what I mean to find http://how2doinvbdotnet.blogspot.ae/2015/07/check-file-is-given-extension-type.html from above question not the MIME type of the file – sreeyushs Aug 02 '15 at 11:01

0 Answers0