DirectoryInfo usage

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Paul K.

    #1

    DirectoryInfo usage

    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(v alue);

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

    SettingInfo.Sou rce=shbrowser.S howBrowser();

    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?
  • Paul K

    #2
    DirectoryInfo usage

    >-----Original Message-----[color=blue]
    >For the past couple weeks, I've been learning C#[/color]
    (already[color=blue]
    >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[/color]
    contains[color=blue]
    >code to set/retrieve application settings:
    >
    >Constructor
    > Source (property) = "C:\\TEST"
    >
    >Source.set
    > DirectoryInfo di=new DirectoryInfo(v alue);
    >
    >At this point, the program runs normally. In a separate
    >section of code, I retrieve a folder path via the
    >SHBrowseForFol der API function. I then attempt to set
    >the Source property of my setting class with the
    >following code:
    >
    > SettingInfo.Sou rce=shbrowser.S howBrowser();
    >
    >The above code returns "C:\TEST". At this point, the
    >DirectoryInf o 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[/color]
    compared[color=blue]
    >the value of the new string with the existing value and
    >they are the same.
    >
    >The bottom line is, the DirectoryInfo class does not[/color]
    seem[color=blue]
    >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?
    >.
    >[/color]

    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.

    Comment

    Working...