Below are the 2 methods which will help you know if the selected document library item is a folder or is the selected list  is a Document library or not.   
- public static class ExtensionMethods  
- {  
-    public static bool IsFolder(this SPListItem item)  
-    {  
-       return (item.Folder != null);  
-    }  
-   
-    public static bool IsDocumentLibrary(this SPList list)  
-    {  
-       return (list.BaseType == SPBaseType.DocumentLibrary);  
-    }     
- }  
 Happy Coding !!!