Hi kana250688,
Add the path in the App.config file by specifying special folder with %%.
Then read the value from App.config file and using RegularExpressions fetch the complete path.
Refer below example.
appSettings
<appSettings>
<add key="DesktopPath" value="%Desktop%\Google Drive2\Katalog\KATALOG BORDIR FINAL\MASTERITEMBORDIRFINAL.accdb"/>
</appSettings>
Code
C#
string desktopPath = ConfigurationManager.AppSettings["DesktopPath"];
string folder = new Regex("([%][^%]+[%])").Replace(desktopPath, (match) =>
{
string specialFolderName = match.Value.Substring(1, match.Value.Length - 2);
Environment.SpecialFolder specialFolder = (Environment.SpecialFolder)Enum.Parse(typeof(Environment.SpecialFolder), specialFolderName, true);
return Environment.GetFolderPath(specialFolder);
});
VB.Net
Dim desktopPath As String = ConfigurationManager.AppSettings("DesktopPath")
Dim folder As String = New Regex("([%][^%]+[%])").Replace(desktopPath, Function(match)
Dim specialFolderName As String = match.Value.Substring(1, match.Value.Length - 2)
Dim specialFolder As Environment.SpecialFolder = CType([Enum].Parse(GetType(Environment.SpecialFolder), specialFolderName, True), Environment.SpecialFolder)
Return Environment.GetFolderPath(specialFolder)
End Function)
Generated path
C:\Users\DELL\Desktop\Google Drive2\Katalog\KATALOG BORDIR FINAL\MASTERITEMBORDIRFINAL.accdb