Hello,
I'm having a problem when trying to use the Directory.Creat eDirectory()
method. It throws a DirectoryNotFou ndException exception. I'll try to
illustrate it:
Suppose you have the following (existing) directory:
d:\Sites\MySite \
And you whant to create the following:
d:\Sites\MySite \MyDir1\MyDir2\
It should be an easy task. Just call CreateDirectory (), like this:
Directory.Creat eDirectory( "d:\Sites\MySit e\MyDir1\MyDir2 \" ) ;
And it will create all missing dirs... in this case "MyDir1" and "MyDir2".
But... if you don't have read permissions of the "d:\" or "d:\Sites\"
directory, a DirectoryNotFou ndException exception is thrown.
I took a look around and many people are facing the same problem. My opinion
is that it is a "big bug" in the DotNet Framework implementation.
The problem is the way the method works... it check if exists and create the
directories starting from the root in this order:
d:\ (Check exists)
d:\Sites\ (Check exists)
d:\Sites\MySite \ (Check exists)
d:\Sites\MySite \MyDir1\ (Check exists and create)
d:\Sites\MySite \MyDir1\MyDir2\ (Check exists and create)
It should do the inverse... starting from the back until the directory is
found (adding the missing ones in and array and after that create then).
It is easy to solve the problem in a controlled environment. You just need
to give Read permissions to the entire path starting from the root (even if
you don't want to do that). But in other cases (like a site hosted in a
server were you have no control), this is impossible to do.
Is there a workaround to create a directory in these situations?
Thanks in advance,
Frederico Caldeira Knabben 4 4598
Hmmm, I just took all read permissions off of a directory I named Test.
Then I used
Directory.Creat eDirectory("C:\ Test\Test\Test\ Test")
and had no problem. Mind you that C:\Test had no read permissoins, and one
by one I used CreateDirectory . Then I deleted everything past the root node
and execute the line above. Either way, no problem.
Is this the exact line that gives you the problems?
Directory.Creat eDirectory( "d:\Sites\MySit e\MyDir1\MyDir2 \" ) ;? If so
there's an error there, consistent with what the documentation says will
happen in such cases http://msdn.microsoft.com/library/de...classtopic.asp
You either need to put a @ at the beginning or use "\\" where you have
single ones. I've tried it a few different ways and can't get it to happen.
But if I put some illegal characters in there, no problemo, kaboom with a
DirectoryNotFou nd
Unless you left something out to replicate this problem, I'm not sure it's a
bug.
--
W.G. Ryan, eMVP http://forums.devbuzz.com/ http://www.knowdotnet.com/williamryan.html http://www.msmvps.com/WilliamRyan/ http://www.devbuzz.com/content/zinc_...center_pg1.asp
"Frederico Caldeira Knabben" <fr****@fredck. com> wrote in message
news:uM******** ********@TK2MSF TNGP10.phx.gbl. .. Hello,
I'm having a problem when trying to use the Directory.Creat eDirectory() method. It throws a DirectoryNotFou ndException exception. I'll try to illustrate it:
Suppose you have the following (existing) directory: d:\Sites\MySite \
And you whant to create the following: d:\Sites\MySite \MyDir1\MyDir2\
It should be an easy task. Just call CreateDirectory (), like this: Directory.Creat eDirectory( "d:\Sites\MySit e\MyDir1\MyDir2 \" ) ;
And it will create all missing dirs... in this case "MyDir1" and "MyDir2".
But... if you don't have read permissions of the "d:\" or "d:\Sites\" directory, a DirectoryNotFou ndException exception is thrown.
I took a look around and many people are facing the same problem. My
opinion is that it is a "big bug" in the DotNet Framework implementation.
The problem is the way the method works... it check if exists and create
the directories starting from the root in this order: d:\ (Check exists) d:\Sites\ (Check exists) d:\Sites\MySite \ (Check exists) d:\Sites\MySite \MyDir1\ (Check exists and create) d:\Sites\MySite \MyDir1\MyDir2\ (Check exists and create)
It should do the inverse... starting from the back until the directory is found (adding the missing ones in and array and after that create then).
It is easy to solve the problem in a controlled environment. You just need to give Read permissions to the entire path starting from the root (even
if you don't want to do that). But in other cases (like a site hosted in a server were you have no control), this is impossible to do.
Is there a workaround to create a directory in these situations?
Thanks in advance, Frederico Caldeira Knabben
I've tried it singleing out each permission. I'm not seeing any
inconsistent behavior. I'm running 2000 Pro .
Also, I did it in C# and using the exact code you posted, I can't even get
it to compile so I'm guessing that's not the actual code..unauthori zed
escape sequence. I've butchered it every way I know how. Now, if I use D:\
which is CD Rom on my machine, I get directoryNotFou nd even though D:\
Exists. According to the documentation, this is consistent.
Cheers,
Bill
--
W.G. Ryan, eMVP http://forums.devbuzz.com/ http://www.knowdotnet.com/williamryan.html http://www.msmvps.com/WilliamRyan/ http://www.devbuzz.com/content/zinc_...center_pg1.asp
"Frederico Caldeira Knabben" <fr****@fredck. com> wrote in message
news:uM******** ********@TK2MSF TNGP10.phx.gbl. .. Hello,
I'm having a problem when trying to use the Directory.Creat eDirectory() method. It throws a DirectoryNotFou ndException exception. I'll try to illustrate it:
Suppose you have the following (existing) directory: d:\Sites\MySite \
And you whant to create the following: d:\Sites\MySite \MyDir1\MyDir2\
It should be an easy task. Just call CreateDirectory (), like this: Directory.Creat eDirectory( "d:\Sites\MySit e\MyDir1\MyDir2 \" ) ;
And it will create all missing dirs... in this case "MyDir1" and "MyDir2".
But... if you don't have read permissions of the "d:\" or "d:\Sites\" directory, a DirectoryNotFou ndException exception is thrown.
I took a look around and many people are facing the same problem. My
opinion is that it is a "big bug" in the DotNet Framework implementation.
The problem is the way the method works... it check if exists and create
the directories starting from the root in this order: d:\ (Check exists) d:\Sites\ (Check exists) d:\Sites\MySite \ (Check exists) d:\Sites\MySite \MyDir1\ (Check exists and create) d:\Sites\MySite \MyDir1\MyDir2\ (Check exists and create)
It should do the inverse... starting from the back until the directory is found (adding the missing ones in and array and after that create then).
It is easy to solve the problem in a controlled environment. You just need to give Read permissions to the entire path starting from the root (even
if you don't want to do that). But in other cases (like a site hosted in a server were you have no control), this is impossible to do.
Is there a workaround to create a directory in these situations?
Thanks in advance, Frederico Caldeira Knabben
Hello William,
Thanks for the prompt response.
Sorry for the slashes... that was just a sample I wrote in the e-mail to
make you understand the problem.
Ok.. I just made a new sample... with a ASPX page... inside the onload
method of the page I put:
System.IO.Direc tory.CreateDire ctory( @"d:\Sites\FCKe ditor\Test\" ) ;
I have just Administrator permissions over the "d:\" and full permissions to
the "IIS_WPG" user starting from "d:\Sites\" ... the following error occours:
[DirectoryNotFou ndException: Could not find a part of the path "D:\".]
If I go to the "d:\" directory and give just "Read" permissions to the
"IIS_WPG" user, everything works just fine.
I'm using Window 2003 with Framework 1.1.
I hope you or someone else can help me.
Best regards,
FredCK
"William Ryan eMVP" <do********@com cast.nospam.net > wrote in message
news:#c******** ******@TK2MSFTN GP09.phx.gbl... Hmmm, I just took all read permissions off of a directory I named Test. Then I used Directory.Creat eDirectory("C:\ Test\Test\Test\ Test")
and had no problem. Mind you that C:\Test had no read permissoins, and
one by one I used CreateDirectory . Then I deleted everything past the root
node and execute the line above. Either way, no problem.
Is this the exact line that gives you the problems? Directory.Creat eDirectory( "d:\Sites\MySit e\MyDir1\MyDir2 \" ) ;? If so there's an error there, consistent with what the documentation says will happen in such cases http://msdn.microsoft.com/library/de...classtopic.asp You either need to put a @ at the beginning or use "\\" where you have single ones. I've tried it a few different ways and can't get it to
happen. But if I put some illegal characters in there, no problemo, kaboom with a DirectoryNotFou nd
Unless you left something out to replicate this problem, I'm not sure it's
a bug. --
W.G. Ryan, eMVP
http://forums.devbuzz.com/ http://www.knowdotnet.com/williamryan.html http://www.msmvps.com/WilliamRyan/ http://www.devbuzz.com/content/zinc_...center_pg1.asp "Frederico Caldeira Knabben" <fr****@fredck. com> wrote in message news:uM******** ********@TK2MSF TNGP10.phx.gbl. .. Hello,
I'm having a problem when trying to use the Directory.Creat eDirectory() method. It throws a DirectoryNotFou ndException exception. I'll try to illustrate it:
Suppose you have the following (existing) directory: d:\Sites\MySite \
And you whant to create the following: d:\Sites\MySite \MyDir1\MyDir2\
It should be an easy task. Just call CreateDirectory (), like this: Directory.Creat eDirectory( "d:\Sites\MySit e\MyDir1\MyDir2 \" ) ;
And it will create all missing dirs... in this case "MyDir1" and
"MyDir2". But... if you don't have read permissions of the "d:\" or "d:\Sites\" directory, a DirectoryNotFou ndException exception is thrown.
I took a look around and many people are facing the same problem. My opinion is that it is a "big bug" in the DotNet Framework implementation.
The problem is the way the method works... it check if exists and create the directories starting from the root in this order: d:\ (Check exists) d:\Sites\ (Check exists) d:\Sites\MySite \ (Check exists) d:\Sites\MySite \MyDir1\ (Check exists and create) d:\Sites\MySite \MyDir1\MyDir2\ (Check exists and create)
It should do the inverse... starting from the back until the directory
is found (adding the missing ones in and array and after that create then).
It is easy to solve the problem in a controlled environment. You just
need to give Read permissions to the entire path starting from the root (even if you don't want to do that). But in other cases (like a site hosted in a server were you have no control), this is impossible to do.
Is there a workaround to create a directory in these situations?
Thanks in advance, Frederico Caldeira Knabben
This is a relatively known .NET bug or "feature".. .
Both Directory.Creat eDirectory(path ) and DirectoryInfo.C reateSubdirecto ry(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 worker 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.Creat eDirectory() with call to unmanaged code, like msvcrt's _mkdir(char*):
[DllImport("msvc rt.dll", SetLastError=tr ue)]
static extern int _mkdir(string path);
....
//replace call to Directory.Creat eDirectory with:
_mkdir(newDirec tory);
....
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
"Frederico Caldeira Knabben" <fr****@fredck. com> wrote in message news:#j******** ******@tk2msftn gp13.phx.gbl... Hello William, Thanks for the prompt response. Sorry for the slashes... that was just a sample I wrote in the e-mail to make you understand the problem. Ok.. I just made a new sample... with a ASPX page... inside the onload method of the page I put: System.IO.Direc tory.CreateDire ctory( @"d:\Sites\FCKe ditor\Test\" ) ; I have just Administrator permissions over the "d:\" and full permissions to the "IIS_WPG" user starting from "d:\Sites\" ... the following error occours: [DirectoryNotFou ndException: Could not find a part of the path "D:\".] If I go to the "d:\" directory and give just "Read" permissions to the "IIS_WPG" user, everything works just fine. I'm using Window 2003 with Framework 1.1. I hope you or someone else can help me. Best regards, FredCK "William Ryan eMVP" <do********@com cast.nospam.net > wrote in message news:#c******** ******@TK2MSFTN GP09.phx.gbl... Hmmm, I just took all read permissions off of a directory I named Test. Then I used Directory.Creat eDirectory("C:\ Test\Test\Test\ Test")
and had no problem. Mind you that C:\Test had no read permissoins, and one by one I used CreateDirectory . Then I deleted everything past the root node and execute the line above. Either way, no problem.
Is this the exact line that gives you the problems? Directory.Creat eDirectory( "d:\Sites\MySit e\MyDir1\MyDir2 \" ) ;? If so there's an error there, consistent with what the documentation says will happen in such cases http://msdn.microsoft.com/library/de...classtopic.asp You either need to put a @ at the beginning or use "\\" where you have single ones. I've tried it a few different ways and can't get it to happen. But if I put some illegal characters in there, no problemo, kaboom with a DirectoryNotFou nd
Unless you left something out to replicate this problem, I'm not sure it's a bug. --
W.G. Ryan, eMVP
http://forums.devbuzz.com/ http://www.knowdotnet.com/williamryan.html http://www.msmvps.com/WilliamRyan/ http://www.devbuzz.com/content/zinc_...center_pg1.asp "Frederico Caldeira Knabben" <fr****@fredck. com> wrote in message news:uM******** ********@TK2MSF TNGP10.phx.gbl. .. Hello,
I'm having a problem when trying to use the Directory.Creat eDirectory() method. It throws a DirectoryNotFou ndException exception. I'll try to illustrate it:
Suppose you have the following (existing) directory: d:\Sites\MySite \
And you whant to create the following: d:\Sites\MySite \MyDir1\MyDir2\
It should be an easy task. Just call CreateDirectory (), like this: Directory.Creat eDirectory( "d:\Sites\MySit e\MyDir1\MyDir2 \" ) ;
And it will create all missing dirs... in this case "MyDir1" and "MyDir2". But... if you don't have read permissions of the "d:\" or "d:\Sites\" directory, a DirectoryNotFou ndException exception is thrown.
I took a look around and many people are facing the same problem. My opinion is that it is a "big bug" in the DotNet Framework implementation.
The problem is the way the method works... it check if exists and create the directories starting from the root in this order: d:\ (Check exists) d:\Sites\ (Check exists) d:\Sites\MySite \ (Check exists) d:\Sites\MySite \MyDir1\ (Check exists and create) d:\Sites\MySite \MyDir1\MyDir2\ (Check exists and create)
It should do the inverse... starting from the back until the directory is found (adding the missing ones in and array and after that create then).
It is easy to solve the problem in a controlled environment. You just need to give Read permissions to the entire path starting from the root (even if you don't want to do that). But in other cases (like a site hosted in a server were you have no control), this is impossible to do.
Is there a workaround to create a directory in these situations?
Thanks in advance, Frederico Caldeira Knabben
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Eran Kampf |
last post by:
I am trying to dynamically create directories in my ASP.NET application (I
am using Server.MapPath("/")+"test" as the folder)
and I am getting a DirectoryNotFoundException saying "Could not find a part
of the path "D:\".
My site is hosted on a public ISP that for obvious security reasons does not
allow my read access above my wwwroot folder which seems to be a problem
when trying to create directories...
Is there any way to solve this?
|
by: GM |
last post by:
Any help is greatly appreciated! I'm up against a meeting deadline.
Directory.CreateDirectory Method throws UnauthorizedAccessException
Here is the path:
"C:\JumpStart\JumpStart\sites\Proto\images\sites.e-Plaza.org\Alece"
Everything before 'Alece' already exists.
|
by: Clinton Frankland |
last post by:
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.
|
by: Frederico Caldeira Knabben |
last post by:
Hello,
I'm having a problem when trying to use the Directory.CreateDirectory()
method. It throws a DirectoryNotFoundException exception. I'll try to
illustrate it:
Suppose you have the following (existing) directory:
d:\Sites\MySite\
And you whant to create the following:
|
by: NewbieDev |
last post by:
Hi,
I call Directory.CreateDirectory and File.Copy from VB.NET with a UNC path
that has a dollar sign ($) - "\\servername\foldername$\childfoldername\" and
it gives me this error message:
System.IO.DirectoryNotFoundException - Could not find a part of the path
"\\servername\foldername$"
Do I need to have an absolute path and not a relative path, which the dollar
| |
by: =?Utf-8?B?Y2FzaGRlc2ttYWM=?= |
last post by:
Hi,
I am having a bit of a nightmare with the following:
if(!Directory.Exists(folderPath))
Directory.CreateDirectory(folderPath);
When I add a watch to this while debugging I see that the value of
folderPath is
|
by: =?Utf-8?B?QnJpYW4gTmljaG9sc29u?= |
last post by:
How do I know which exceptions a function throws? In my application, I make
a call to DirectoryInfo.GetDirectories("\\NetworkPath\Path"). I check for
System.IO.DirectoryNotFoundException and Security.SecurityException (which I
found in the Object Browser with VS2005). If Path is invalid, the block
catches System.IO.DirectoryNotFoundException as expected. However, if
NetworkPath is invalid, it instead throws a System.IO.IOException,...
|
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |