473,569 Members | 2,698 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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?
Nov 15 '05 #1
1 5039
>-----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(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 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
4682
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. Unfortunately it appears that I cannot have something like: dirInfo.GetFiles("*.jpg;*.gif"); // where dirInfo is of type DirectoryInfo
1
2603
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 files and my progress in the recursion. I use a while loop to manage the folder-subfolder drill-down. Each pass through the while loop creates a new...
1
10433
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 DirectoryInfo("\\\\server_name\\shared_folder_name"); FileInfo fiArr = folder.GetFiles();
8
1894
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 directory info that would contain the file name without the extension. Can I add an attribute or an entry to accomplish this? If so, how, if not, is...
3
2374
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 ; ccc++ ) { System.Web.HttpResponse.Response.Write( "<a href=\"" + Request.MapPath(".") + "/" + HttpUtility.HtmlEncode(ppp.Name) + "\">link</a>" );
2
2177
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")) For Each fsi In dInfo.FileSystemInfo
0
1943
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 = new DirectoryInfo(EmailConfiguration.EmailImagesFolderRootPath + "\\Event_" + eventId);
3
3080
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 = new DirectoryInfo("C:\\Temp\\");
5
6136
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, ReadOnly, etc.). The problem I'm having is in identifying when a FileSystemInfo entry is a FileInfo or a DirectoryInfo type. I get the rare, and yet...
0
7698
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8122
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7673
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5513
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1213
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.