Search code examples
c#filefile-extension

How to find the extension of a file in C#?


In my web application (asp.net,c#) I am uploading video file in a page but I want to upload only flv videos. How can I restrict when I upload other extension videos?


Solution

  • Path.GetExtension

    string myFilePath = @"C:\MyFile.txt";
    string ext = Path.GetExtension(myFilePath);
    // ext would be ".txt"