C#: How do you get Application data folder path for current user?

Its really simple actually

You should be looking at this Global class

[geshi lang=”csharp” nums=”1″ target=”_self” ]

Environment

This class has a function called called GetFolderPath. This is how you use it

[geshi lang=”csharp” nums=”1″ target=”_self” ]

Environment.GetFolderPath();

This method takes Environment.SpecialFolder (Type Enum) as an argument.

So for final solution you should be looking at this

[geshi lang=”csharp” nums=”1″ target=”_self” ]

Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData);
// thus if you want to read a file from this folder you can initialize a variable as

var fileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "YOUR_FILE_NAME.EXTENSION")

MSDN Resources:

Environment.SpecialFoler Enumeration is explained here

http://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx

Environment.GetFolderPath Method is explained here

http://msdn.microsoft.com/en-us/library/dd992682.aspx

P.S.: I am not a C# expert but occasional C# user for smaller projects.

I hope this helps

 

 

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.