473,386 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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(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?
Nov 15 '05 #1
1 5026
>-----Original Message-----
For the past couple weeks, I've been learning C# (alreadyknow 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 containscode 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 comparedthe value of the new string with the existing value and
they are the same.

The bottom line is, the DirectoryInfo class does not seemto 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.
Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Pluto | last post by:
Hi, I want to get a list of files matching certain extensions, such as "*.jpg;*.gif" (i.e. all files ending with .jpg and .gif). I was using DirectoryInfo.GetFiles(string) method....
1
by: Vagabond Software | last post by:
I am recursing through ALL folders and sub-folders below a certain level to list all the files of a certain type in those folders. I use two ArrayLists, alFiles and alFolders, to track matching...
1
by: siddharth_jain_1 | last post by:
Hello I am trying to get a list of shared files and subdirectories in a particular folder on a server. For this I am using DirectoryInfo in the following way. DirectoryInfo folder = new...
8
by: Lyners | last post by:
I have code that retrieves all of the file names within a directory. After retriving them, I display the information in a datagrid. What I would like to do is add an extra output column on the...
3
by: xenophon | last post by:
This following innocuous code: System.IO.DirectoryInfo fff = new System.IO.DirectoryInfo(); System.IO.FileInfo ppp = fff.GetFiles( Request.MapPath(".") ); for( int ccc=0 ; ccc < ppp.Length ;...
2
by: rn5a | last post by:
Suppose I have the following code: <script runat="server"> Sub Page_Load(.....) Dim dInfo As DirectoryInfo Dim fsi As FileSystemInfo dInfo = New DirectoryInfo(Server.MapPath("Folder1")) ...
0
by: MP | last post by:
Hi, I am getting the Access denied Error on a folder after I try to delete a folder that contains some files through my ASP.NET Application. Following is my code DirectoryInfo directoryInfo...
3
by: Steve Kershaw | last post by:
Hi, I need a way to bind a DirectoryInfo array to a GridView without any errors. The code I'm using to create the DirectoryInfo array is: // Define the current directory DirectoryInfo dir...
5
by: Tom P. | last post by:
I am having the following problem: I create a FileSystemWatcher and wait for events. When the event does happen I refresh a FileSystemInfo list and set properties accordingly (IsFile, IsDir,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.