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

111 views Asked by At

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.

1

There are 1 answers

4
Sahil Manchanda On BEST ANSWER

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