Search code examples
.netmdf

Winforms application : How to save .mdf to Windows %USERPROFILE% folder?


I have a Winforms application and I would like to save my database.mdf to %USERPROFILE% folder. Does anyone know what i need to write to the connection string for this to work? Simply using %USERPROFILE% does not work.


Solution

  • You can refer to this

       String query = "%USERPROFILE%";
       String pathOfUserProfile = Environment.ExpandEnvironmentVariables(query);
       Console.WriteLine(pathofUserProfile);
    

    You will get the path in string. Now simply create your connection string as usual