DirectoryNotFoundException - Could not find a part of the path "D:\".

DirectoryNotFoundException - Could not find a part of the path "D:\".

Post by Tom Voge » Mon, 03 May 2004 03:52:45


Creating a subfolder within my ASP.NET application folder fails with the
above error, but only at my hosting provider. The command:
Directory.CreateDirectory(path)

Path is set to 'D:\appfolder\test2'. ASPNET has full control on the
application folder.

Any ideas why this fails?

- Tom
 
 
 

DirectoryNotFoundException - Could not find a part of the path "D:\".

Post by Natty Gu » Tue, 04 May 2004 12:57:26

Hi,

are you sure your provider has D:/ driver on the host server ?

Natty Gur[MVP]

blog : http://www.yqcomputer.com/
Mobile: +972-(0)58-888377


*** Sent via Developersdex http://www.yqcomputer.com/ ***
Don't just participate in USENET...get rewarded for it!

 
 
 

DirectoryNotFoundException - Could not find a part of the path "D:\".

Post by Tom Voge » Tue, 04 May 2004 17:04:49

Yes. It is confirmed in the documentation of the provider. And I get it from
the AppDomain.CurrentDomain.BaseDir.

Could it be, that ASPNET need browsing rights on the D drive?

- Tom
 
 
 

DirectoryNotFoundException - Could not find a part of the path "D:\".

Post by Tom Voge » Tue, 04 May 2004 18:59:45

The following code fails with above error message:
parentpath = AppDomain.CurrentDomain.BaseDirectory + "_Portals/";
s = System.IO.Path.Combine(parentpath,"_test");
System.IO.Directory.CreateDirectory(s);

I've debugged the problem at my hosting provider by creating a test page and
using the Directory and DirectoryInfo classes:

Creating Folder "D:/portalapp/public_html/_Portals/_test" failed:
Could not find a part of the path "D:/".

Current Folder C:\WINNT\system32

Drives: A:\C:\D:\Z:\

Parentfolder D:\portalapp\public_html\_Portals exists
Parentfolder D:\portalapp\public_html exists
Parentfolder D:\portalapp exists
Parentfolder D:\ does not exist.
Rootfolder D:\ does not exist.

If anybody has an idea why ASPNET can see the D:\ drive but doesn't seem to
find it when creating a subdirectory, please let me know.

- Tom
 
 
 

DirectoryNotFoundException - Could not find a part of the path "D:\".

Post by Natty Gu » Wed, 05 May 2004 13:37:15

Tom hi,

I can't get something. You are writing that D driver doesn't exist
"Parentfolder D:\ does not exist Rootfolder D:\ does not exist" and you
expect .Net to create sub directory there? Maybe d:/ is mapping to
remote storage (NAS, SAN). If so ASP.NET defaults user don't have rights
to access remote resources.

Natty Gur[MVP]

blog : http://www.yqcomputer.com/
Mobile: +972-(0)58-888377


*** Sent via Developersdex http://www.yqcomputer.com/ ***
Don't just participate in USENET...get rewarded for it!
 
 
 

DirectoryNotFoundException - Could not find a part of the path "D:\".

Post by Dmitry Kul » Tue, 31 Aug 2004 12:05:25

This is a relatively known .NET bug or "feature"...



Both Directory.CreateDirectory(path) and
DirectoryInfo.CreateSubdirectory(path) require user to have Read access to
the drive's root directory (i.e. <Drive>:\).



Many ASP.NET hosting providers (especially those running Windows 2003
Server) will not allow user running ASP.NET working process read access to
the root folder, so CreateDirectory will always fail. You can not blame
hosting providers - they do right thing, securing shared environment from
users with malicious intents.



The only workaround I have found is to replace call to
Directory.CreateDirectory() with call to unmanaged code, like msvcrt's
_mkdir(char*):



[DllImport("msvcrt.dll", SetLastError=true)]

static extern int _mkdir(string path);



...

//replace call to Directory.CreateDirectory with:

_mkdir(newDirectory);

...



This will work only if your code is granted "Allow Calls to Unmanaged Code"
permission but most hosting environments allow that.



You can find more details in my recent Blog entry at
http://www.yqcomputer.com/



Dmitry Kulakovsky





and
to