CommonAppDataPath without version RRS feed

  • Question

  • Hi,

    When I try to read the CommonAppDataPath It returns the path with version number of my application.

    How can I get the CommonAppDataPath but without the version?



    Friday, February 6, 2015 11:51 PM


  • I assume you mean you are doing something like this:

    Dim comAppData As String = Application.CommonAppDataPath

    And getting something like "C:\ProgramData\AppName\AppName\"

    And you just want "C:\ProgramData\AppName\AppName"

    You could use the LastIndexOf and SubString methods to do that, but I think the best way to get the parent directory is

    Dim comAppData As String = Application.CommonAppDataPath
    Dim comAppParent As String = System.IO.Path.GetDirectoryName(comAppData)

    or in C#

    string comAppData = Application.CommonAppDataPath;
    string comAppParent = System.IO.Path.GetDirectoryName(comAppData);

    [Edit] Note that You shouldn't be relying on what your think the directory structure is. Application.CommonAppDataPath is provided for you to use. In your current version of Windows, it's parent may be unique to your application (but not any particular version of it). In another version of Windows, it may not. You should really only use the directories provided by the methods and properties you can call. In other words, you probably shouldn't do what you are trying to do.
    • Edited by Blackwood Saturday, February 7, 2015 2:56 AM Add note.
    • Marked as answer by Fred BaoModerator Monday, February 16, 2015 9:54 AM
    Saturday, February 7, 2015 1:35 AM