Apoorv Apoorv - 4 months ago 13
Vb.net Question

Programatically get the folder location

I have this VB code which on debugging gets me the following location


C:\Users\AUpadhyay\AppData\Roaming\Sterling Ultra Precision\Power
Suite\2.7.0.0


The VB Code is

AppPath = System.IO.Directory.GetParent(My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData).ToString


I was trying to reach the same directory using the below C# code but the output is


C:\Users\AUpadhyay\AppData


The C# code is

AppPath = System.IO.Directory.GetParent(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)).ToString();


What would be the line of code to get the same directory address ?

Answer

Application.UserAppDataPath would be your solution.

It's accessible from both VB.NET and C#, and it returns:

C:\Users\[Your user name]\AppData\Roaming\[Your company name]\[Your product name]\[Your product version]

Result from C#:

Application.UserAppDataPath in a MessageBox

Comments