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

T

Tom Vogel

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
 
T

Tom Vogel

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
 
T

Tom Vogel

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
 
N

Natty Gur

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://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
 
D

Dmitry Kulakovsky

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://hatka.net/wlogdev/archive/2004/08/29/178.aspx



Dmitry Kulakovsky
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top