none
How to get the Full path of any Folder in IVsSolution (IVsHierarchy)? RRS feed

  • Question

  • I am trying to get the full path of any folders in a ivshierarchy or ivssolution.

    I am able to achieve that using GetCanonicalName(...)
    method. But it returns the path in lower case completely...

    For example if my folder path is "C:\\My VS Projects\\Project1\\MyFolder" then the above method returns "c:\\my vsprojects\\project1\\myfolder"...

    I couldn't get the actual case-sentive path for my folder. I need this because i need to display that in UI.

    I tried passing canonical name to Path.GetFullPath(...) but it doesn't help...

    For files, i know we have IVsProject.GetMkDocument(...) method. But i couldn't find any other way to get folder path (case-sensitive)

    Thanks in advance

    karthik

    Tuesday, April 14, 2009 6:54 PM

Answers

  • You have to split the full path on the separator character(s), then use the Directory.GetDirectories method to enumerate the available folders, then select the folder that matches the name of your path element (case-insensitive comparison). The directories returned from Directory.GetDirectories have the correct case.
    • Marked as answer by Wesley Yao Tuesday, April 21, 2009 3:11 AM
    Friday, April 17, 2009 9:36 PM
  • This works if you have the full path:

    public static string FixPathCase( string fullPath )
    {
        return fullPath
            .Split( System.IO.Path.DirectorySeparatorChar, System.IO.Path.AltDirectorySeparatorChar )
            .Aggregate( string.Empty,
                ( accum, element ) =>
                {
                    if ( string.IsNullOrEmpty( accum ) )
                        return element + System.IO.Path.DirectorySeparatorChar;
                    return System.IO.Directory.GetFileSystemEntries( accum, element ).First();
                }
                );
    }
    
    • Proposed as answer by Sam Harwell Friday, April 17, 2009 10:24 PM
    • Marked as answer by Wesley Yao Tuesday, April 21, 2009 3:11 AM
    Friday, April 17, 2009 9:59 PM

All replies

  • Wednesday, April 15, 2009 12:49 AM
  • You have to split the full path on the separator character(s), then use the Directory.GetDirectories method to enumerate the available folders, then select the folder that matches the name of your path element (case-insensitive comparison). The directories returned from Directory.GetDirectories have the correct case.
    • Marked as answer by Wesley Yao Tuesday, April 21, 2009 3:11 AM
    Friday, April 17, 2009 9:36 PM
  • This works if you have the full path:

    public static string FixPathCase( string fullPath )
    {
        return fullPath
            .Split( System.IO.Path.DirectorySeparatorChar, System.IO.Path.AltDirectorySeparatorChar )
            .Aggregate( string.Empty,
                ( accum, element ) =>
                {
                    if ( string.IsNullOrEmpty( accum ) )
                        return element + System.IO.Path.DirectorySeparatorChar;
                    return System.IO.Directory.GetFileSystemEntries( accum, element ).First();
                }
                );
    }
    
    • Proposed as answer by Sam Harwell Friday, April 17, 2009 10:24 PM
    • Marked as answer by Wesley Yao Tuesday, April 21, 2009 3:11 AM
    Friday, April 17, 2009 9:59 PM