See the question and my original answer on StackOverflow

The following code will get you 3 information:

// get solution reference from a service provider (package, etc.)
var solution = (IVsSolution)ServiceProvider.GetService(typeof(SVsSolution));

solution.GetSolutionInfo(out string dir, out string file, out string ops);
// dir will contain the solution's directory path (folder in the open folder case)

solution.GetProperty((int)__VSPROPID.VSPROPID_IsSolutionOpen, out object open);
bool isOpen = (bool)open; // is the solution open?

// __VSPROPID7 needs Microsoft.VisualStudio.Shell.Interop.15.0.DesignTime.dll
solution.GetProperty((int)__VSPROPID7.VSPROPID_IsInOpenFolderMode, out object folderMode);
bool isInFolderMode = (bool)folderMode; // is the solution in folder mode?