DirectoryInfo usage

  • Thread starter Thread starter Paul K.
  • Start date Start date
P

Paul K.

For the past couple weeks, I've been learning C# (already
know basic C++) and .NET. In the middle of re-coding a
small application I made previously in VB, I am running
into a problem.

Here is the code in my CSettingInfo class, which contains
code to set/retrieve application settings:

Constructor
Source (property) = "C:\\TEST"

Source.set
DirectoryInfo di=new DirectoryInfo(value);

At this point, the program runs normally. In a separate
section of code, I retrieve a folder path via the
SHBrowseForFolder API function. I then attempt to set
the Source property of my setting class with the
following code:

SettingInfo.Source=shbrowser.ShowBrowser();

The above code returns "C:\TEST". At this point, the
DirectoryInfo object in the set function for the Source
property throws the exception "illegal characters in
path". I have tried using the Replace function of the
string class to replace single slashes with double
slashes and have gotten the same result. I have compared
the value of the new string with the existing value and
they are the same.

The bottom line is, the DirectoryInfo class does not seem
to like either "C:\TEST" or "C:\\TEST", but is okay with
hard-coded values. Does anyone have a suggestion as to
what I am doing incorrectly?
 
-----Original Message-----
For the past couple weeks, I've been learning C# (already
know basic C++) and .NET. In the middle of re-coding a
small application I made previously in VB, I am running
into a problem.

Here is the code in my CSettingInfo class, which contains
code to set/retrieve application settings:

Constructor
Source (property) = "C:\\TEST"

Source.set
DirectoryInfo di=new DirectoryInfo(value);

At this point, the program runs normally. In a separate
section of code, I retrieve a folder path via the
SHBrowseForFolder API function. I then attempt to set
the Source property of my setting class with the
following code:

SettingInfo.Source=shbrowser.ShowBrowser();

The above code returns "C:\TEST". At this point, the
DirectoryInfo object in the set function for the Source
property throws the exception "illegal characters in
path". I have tried using the Replace function of the
string class to replace single slashes with double
slashes and have gotten the same result. I have compared
the value of the new string with the existing value and
they are the same.

The bottom line is, the DirectoryInfo class does not seem
to like either "C:\TEST" or "C:\\TEST", but is okay with
hard-coded values. Does anyone have a suggestion as to
what I am doing incorrectly?
.

As an add-on, if I type a path (either "C:\TEST"
or "C:\\TEST") in a textbox, the application doesn't
throw an exception.
 
Back
Top