none
How to access AppData folder

    Question

  • What is the best way to programmatically find/access a user's AppData folder(c:\users\[username]\AppData) in .net C#? 
    Tuesday, April 18, 2017 2:34 PM

All replies

  • Hi!

    You have the same post in this link : http://stackoverflow.com/questions/1225829/how-to-get-users-application-data-folder-using-c

    But what kind of application do you want to develop?

    Hope it wil be useful.

    If it's good for you, can you mark this answer as answer of your question please?

    Follow me on twitter : https://twitter.com/NordineMhoumadi


    Download my NEW FREE application MCP PREPARATION in the Windows 10 Store for preparing your Microsoft Certification or test your skills in Microsoft Technologies;

    Tuesday, April 18, 2017 2:47 PM
  • You can do  something like :

    String sPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
    String sUserName = Environment.UserName;
    string[] sPathLines = sPath.Split(new string[] { sUserName }, StringSplitOptions.RemoveEmptyEntries);
    foreach (string sLine in sPathLines)
    {
        Console.WriteLine(sLine);
    }

    Tuesday, April 18, 2017 2:48 PM
  • Thanks for the sample code.

    Unfortunately, Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) returns the path to "AppData\Roaming". I need AppData or AppData\LocalLow.

    I know I could just strip off the "\Roaming" off of the returned path, or possibly add on "\..\LocalLow" but those seem like a bit of a kludge.

    Tuesday, April 18, 2017 3:10 PM
  • You can replace ApplicationData by LocalApplicationData
    Tuesday, April 18, 2017 3:23 PM
  • You can replace ApplicationData by LocalApplicationData
    That returns ...\AppData\Local
    Tuesday, April 18, 2017 3:30 PM
  • If you really want LocalLow, you can use Shell APIs like SHGetKnownFolderPath, (sample in this thread for example)


    • Edited by Castorix31 Tuesday, April 18, 2017 3:41 PM
    Tuesday, April 18, 2017 3:41 PM
  • You can replace ApplicationData by LocalApplicationData

    That returns ...\AppData\Local
    I guess you can do this. Tried it with Directory.Exists and it works.
    string path = (Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)+"\\Appdata\\LocalLow")


    • Edited by webik150 Tuesday, April 18, 2017 4:04 PM
    Tuesday, April 18, 2017 4:04 PM
  • You can replace ApplicationData by LocalApplicationData

    That returns ...\AppData\Local

    I guess you can do this. Tried it with Directory.Exists and it works.
    string path = (Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)+"\\Appdata\\LocalLow")


    But LocalLow is a special folder(FOLDERID_LocalAppDataLow)

    and the path can be different

    Tuesday, April 18, 2017 4:11 PM

  • I guess you can do this. Tried it with Directory.Exists and it works.

    string path = (Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)+"\\Appdata\\LocalLow")

    That seems to be the most elegant solution so far.

    Thanks!

    • Edited by Pfredd Mudd Tuesday, April 18, 2017 6:12 PM
    Tuesday, April 18, 2017 6:11 PM

  • I guess you can do this. Tried it with Directory.Exists and it works.

    string path = (Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)+"\\Appdata\\LocalLow")

    That seems to be the most elegant solution so far.

    Thanks!

    No.

    As said above, anyone can change this folder and it won't work if it is hardcoded

    Tuesday, April 18, 2017 7:15 PM