472,353 Members | 1,908 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

CreateDirectory() - Could not find a part of the path "D:\".

Hi,

On a Windows 2000 Server when attempting to use
System.IO.Directory.CreateDirectory(string.concat( Server.MapPath(""),
"\verify"))
I receive a System.IO.DirectoryNotFoundException error: Could not find a
part of the path "D:\".

The full path is "D:\hshome\clinton\test.gotchasoft.com\verify"
The web is running using impersonation as a user on the local machine.
The user has no access to d:\, d:\hshome, or d:\hshome\clinton.
The user has modify access to d:\hshome\clinton\test.gotchasoft.com.

Using the old Scripting.FileSystemObject.CreateFolder() using the same path
name works fine.
System.IO.Directory.DeleteDirectory() using the same path once created works
fine.
System.IO.Directory.SetCurrentDirectory(server.map path("")) raises a similar
error but lists the entire folder structure rather than just the root.

I've seen similar posts accross the web, and have tried the following
suggestions:
Granting the "Bypass traverse checking" right to Everyone had no effect;
Granting the "Read Extended Attributes" to the D:\ drive had no effect.

This error is confirmed accross 38 Windows 2000 servers in an H-Sphere
(psoft.net) cluster, all with .NET Framework v1.1 installed.

Any help would be appreciated!

Clinton Frankland
Nov 19 '05 #1
9 13224
Hi Clinton,

Welcome to ASP.NET newsgroup.
From your description, when you're using Directory.CreateDirectory to
create sub dirs through the path retrieved by the Server.MapPath("") , you
got
========
System.IO.DirectoryNotFoundException error: Could not find a part of the
path "D:\".
========

error. Also, you're suffering the problem on many other machines with the
same environement, yes?

Based on my loal test and the code sinppet, the problem is likely caused by
something with your environment. Would you help me confirm the following
things:

1. Does the problem occurs if you directly pass the full physical Path of
your application's virtual dir to the CreateDirectory function?

2. If still occurs, we may do some check on permission. How about turn off
impersonate and use the default process identity(should be machine\aspnet
for win2k server) and grant "modify/write" permission to that account. Test
again to see whether that can work. ( You can also test creating directory
through passing full qualified path when you swtich the process identity
and turn off impersonate).

BTW, to get the physical path of the root dir of our ASP.NET application,
we can use the
Server.MapPath("~/"), this will be better than using the empty string which
only retrieve the relative path the current directory.

Please feel free to let me know if you got any new findings or need any
further help. Thanks,
Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


Nov 19 '05 #2
Yes, the all the machines in the same environment have the same problem.

If I pass the full physical path the problem still occurs. Even testing
using the full string
Directory.CreateDirectory("D:\hshome\clinton\test. gotchasoft.com\verify")
fails with the same error message.

This problem originally started using the default aspnet user (which again
did not have read access to the d:\ folder).

If I grant read access to d:\, d:\hshome, and d:\hshome\clinton; the problem
goes away.

Nov 19 '05 #3
Hi Clinton,

Thanks for your response. I think read access is necessary not only for the
application's virtual dir but also for the parent and root dir. This is
because the ASP.NET runtime will need to do monitoring on appliation's dir
and also parent dir (such as monitor the changing of web.config in all the
up level folders). Though I'm not sure this is the direct cause, but I'm
sure the read access must be granted to your asp.net 's executing account.

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


Nov 19 '05 #4
I have just finished troubleshooting the same issue on one of our sites.
This concerns me for two reasons:

1) Misleading Exception thrown

Since the issue is caused by lack of permission for the ASPNET acct. to read
the parent folders, I would expect an UnauthorizedAccessException, not
DirectoryNotFoundException.

2) Non-standard behavior of permissions

If I create C:\PermTest\ and C:\PermTest\user then grant full rights to the
\user folder and no read permission to C:\PermTest. I can view and create
folders, files, etc. in C:\PermTest\user, but cannot view anything in
C:\PermTest. (Tested using a windows login acct. not the ASPNET acct.)

I would expect this same behavior with Directory.CreateDirectory.

Insight from other developers implies that the CreateDirectory function's
behavior of creating a full path, not just the last directory in the given
path, is what is causing this. If it tries to look in C:\ (or D:\) to see if
the folder exists and is denied read access, then it appears to be failing
the CreateDirectory funciton entirely. For a good example see
http://hatka.net/wlogdev/archive/2004/08/29/178.aspx

Maybe a good solution would be two functions? CreateDirectory(string path) -
behaving this exact way for backwards compat. and CreateDirectory(string
path, CreateDirectoryBehavior.LastDirectoryOnly); or something to that affect.

Bryan Gerber
ASP.NET Developer

"Steven Cheng[MSFT]" wrote:
Hi Clinton,

Thanks for your response. I think read access is necessary not only for the
application's virtual dir but also for the parent and root dir. This is
because the ASP.NET runtime will need to do monitoring on appliation's dir
and also parent dir (such as monitor the changing of web.config in all the
up level folders). Though I'm not sure this is the direct cause, but I'm
sure the read access must be granted to your asp.net 's executing account.

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


Nov 19 '05 #5
I just got done troubleshooting this error on one of our web applications.
There is a good source for this error and a good possible explanation at
http://hatka.net/wlogdev/archive/2004/08/29/178.aspx

This behavior concerns me for two reasons:

1) Wrong exception thrown

If the error is due to a lack of permission, UnauthorizedAccessException
should be thrown, NOT DirectoryNotFoundException

2) non-standard permission behavior

If I create a new windows login and the following folders:

C:\PermTest\
C:\PermTest\user

Granting full perms to new user on \user folder and no perms on C:\PermTest,
the user CAN write files and create directories in C:\PermTest\user, but
cannot read anything in C:\PermTest.
If I were fixing this, I might overload the CreateDirectory function to
support both behaviors:
CreateDirectory(string path) could remain as is
CreateDirectory(string path, CreateDirectoryBehavior.CreateLastOnly) could
ignore the first part of the path and just create the final folder in the
path string.

At the very least, I think that the MSDN documentation for
Directory.CreateDirectory should explicity mention this behavior at the top
of the page instead of implying it in the remarks section.

Nov 19 '05 #6
Sorry for double post. Apparently, the post page lied to me when it said
there was an error posting my first message.
Nov 19 '05 #7
I had the same problem ("DirectoryNotFoundException - Could not find a
part of the path"), and found the remedy. If you search around, you'll
find that whenever this problem occurs, it's when someone is using a
drive other than C: - and usually these are locked down drives.

Apparently, Directory.CreateDirectory() requires read and list contents
permissions on the root of the drive where the directory is being
created. The fix for me was to copy the permissions that I found on
the root of my C: drive to the root of my F: ( could be D:, etc) drive.

There is one permission set for Everyone on the C: drive, for "this
folder only" (not inherited), that gives Read & Execute permissions.
When I reproduced that permission set on my F: drive, this problem went
away. An important point is that by making this permission not
inherited into child folders and files, I don't have to worry about
opening up a big security hole.

Hope that helps,
John Crim
WebRelevance, Inc.

Nov 19 '05 #8
Dangit!!! I didn't think Google groups would post my email address....

Nov 19 '05 #9
I had the same problem ("DirectoryNotFoundException - Could not find a
part of the path"), and discovered the fix. If you search around,
you'll
find that whenever this problem occurs, it's when someone is using a
drive other than C: - and usually these are locked down drives.

Apparently, Directory.CreateDirectory() requires read and list contents

permissions on the root of the drive where the directory is being
created. The fix for me was to copy the permissions that I found on
the root of my C: drive to the root of my F: ( could be D:, etc) drive.
There is one permission set for Everyone on the C: drive, for "this
folder only" (not inherited), that gives Read & Execute permissions.
When I reproduced that permission set on my F: drive, this problem went

away. An important point is that by making this permission not
inherited into child folders and files, I don't have to worry about
opening up a big security hole.
Hope that helps,
John Crim
WebRelevance, Inc.

Nov 19 '05 #10

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

Similar topics

2
by: Karl Koscher | last post by:
I'm trying to communicate with a USB device using C#. I'm able to determine the device path using P/Invoke and SetupDiGetClassDevs,...
3
by: Dmitry Jouravlev | last post by:
Hi, I have a number of C++ solutions in Visual Studio .NET and when i compile them using "Whole Program Optimization", certain projects report a...
10
by: Alpha | last post by:
I use FolderBrowserDlg for user to select a folder path then store it in the sql table. I then retrieve it to concatenate in a sqlcommand text to...
1
by: ±ù÷¢ | last post by:
I have a standard vb crystal reports viewer control on a web form with just the one simple report bound to it. when I run the project I get the...
0
by: Martin | last post by:
Is this a known problem? Server Error in '/' Application. Could not find a part of the path...
1
by: Michiel Schaeverbeke | last post by:
Hi, I'm trying to reach an xml file from within a web application. The file is physically on a different server. When I try to reach it using...
0
by: haylow | last post by:
Hi I am new to ASP.NET and am working on an application that runs on a webserver. The user will open up the web interface in a browser on their...
2
by: Guoqi Zheng | last post by:
Dear sir, I am trying to save a binary data by below script, however,it always give me an error of "Could not find a part of the path "C:\temp\"....
3
by: Nitinkcv | last post by:
Hi, While trying to run my app im getting the error Could not find a part of the path "c:\inetpub\wwwroot\Do not Delete\dbglobal.config". I...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

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.