In my c# code when I used Path.GetExtension , It is showing "Path does not exist in current context". Seems libraries for Path does not exist in current application. But I searched and found Path class defined in System.IO and System.IO is by default part of our application. After included System.IO the error exist.
            Asked
            
        
        
            Active
            
        
            Viewed 1.1k times
        
    9
            
            
        - 
                    1do you have `using System.IO;` on the beginning of your .cs file? – Nino Jun 29 '17 at 07:22
- 
                    1Yes you need to use namespace System.IO; then it will work – Laxman Gite Jun 29 '17 at 07:23
- 
                    1Please post the exact compiler error you get. Also, post the exact line of code (or lines of code) that give you that error. – Lasse V. Karlsen Jun 29 '17 at 07:30
- 
                    1The library for Path is the core .NET library, so it's *always* available. Obviously something is wrong with your code. Post your code, the *full* compile error and the line where it occured – Panagiotis Kanavos Jun 29 '17 at 07:42
1 Answers
13
            
            
        You need to add namespace
using System.IO;
And your path should be :
string str= Path.GetExtension(FileUpload1.PostedFile.FileName);
Second way :
string str= System.IO.Path.GetExtension(FileUpload1.PostedFile.FileName);
Then it will work.
Cheers !!
 
    
    
        Laxman Gite
        
- 2,248
- 2
- 15
- 23
