Use environment variables in .NET

Use environment variables in .NET

Ever wanted to use environment variables in .NET ? Just using “%UserProfile%\path to file” won’t work as it will be added to the startup path.
Use this little “trick” to use those variables:

Environment.ExpandEnvironmentVariables("%UserProfile%\Desktop\myfile.txt");

Leave a Reply

Your email address will not be published. Required fields are marked *

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