How do i use a string file path in settings so i can get that path useable in my code

Viewed 60

I'm writing an application using C#, normally a VB user, so have been thrown a few easily solveable curve balls with the syntax differences, until this...

I have a couple of string paths in my Application Settings e.g. *AppSetting_SourceFolder=C:\SourceFolder* and *AppSetting_DestFolder=C:\DestFolder\Processed*

in my code I have a FileSystemWatcher that is watching the source folder and for certain files that appear in the source folder, they are processed and moved to the destination folder. My issue is that when I pull my folders names from the settings into variables or the FileSystemWatcher they don't comeout as expected.

string sSourcePath = MyNameSpace.Properties.Settings.Default.AppSetting_SourceFolder;
string sDestPath = MyNameSpace.Properties.Settings.Default.AppSetting_DestFolder;

and I watch the variables at runtime is see that sSourcePath contains "C:\\SourceFolder\\" and sDestFolder contains "C:\\DestFolder\\Processed\\"

I've looked at using the string literal @ infront of my setting reference:

string sSourcePath = @MyNameSpace.Properties.Settings.Default.AppSetting_SourceFolder;
string sDestPath = @MyNameSpace.Properties.Settings.Default.AppSetting_DestFolder;

and also infront of my variable name:

string @sSourcePath = MyNameSpace.Properties.Settings.Default.AppSetting_SourceFolder;
string @sDestPath = MyNameSpace.Properties.Settings.Default.AppSetting_DestFolder;

and also infront of my both parts:

string @sSourcePath = @MyNameSpace.Properties.Settings.Default.AppSetting_SourceFolder;
string @sDestPath = @MyNameSpace.Properties.Settings.Default.AppSetting_DestFolder;

but the outcome doesn't change. What do i have to do to get rid of the extra \'s?

Just to note, when I watch @MyNameSpace.Properties.Settings.Default.AppSetting_SourceFolder and @MyNameSpace.Properties.Settings.Default.AppSetting_DestFolder; the result is the same (lots of double \'s).

What am doing (or not doing) wrong? Thanks Steve

1 Answers

These are not double backslashes. When you watch the value by either hovering your mouse pointer at the variable or in the Watch panel, all the special characters that need to be escaped are shown there with additional backslash.

If you want to see processed string without additional backslashes, click the magnifying glass icon near the value.

Watch panel - magnifying glass button

Text Visualizer after clicking the icon

Related