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
"Tom Vogel" <tv**@yahoo.com> wrote in message
news:O2*************@TK2MSFTNGP09.phx.gbl...
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
"Natty Gur" <na***@dao2com.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl... Hi,
are you sure your provider has D:/ driver on the host server ?
Natty Gur[MVP]
blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!