473,394 Members | 1,694 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

problems creating lots of directories

i'm really stuck with this one can anyone help!

i have a website that uses c#. it creates a series of directories and
files from an xml source. when the xml changes, the directory that the
change applies to is deleted and recreated. All the children for that
directory are also re created (as the parent directory then has a
different name).

the problem i have is that *sometimes* the files or directories don't
get created. It either gets stuck creating the file or the directory.
i get either an io exception or a security exception. the .net runtime
has full access to the file system so it isn't a general permissions
thing. the securiy exception occurs on the last file or direcotory
created.
the last file or directory it creates before the exception is throw is
normally inaccessible and will be locked. i won't be able to delete it
manually in explorer - it will say i don't have permission even if i
am the administrator. i won't even be able to view the security info
or anything about it. After a while the file or folder will disappear
or become deletable.

No one else is using these files since it is on my test machine so it
can't be because of that.

the code i am using to create the direcotory and file is as follows.
this is run in a for loop - each xml node has directory name which
forms the path:

System.IO.DirectoryInfo di = new
DirectoryInfo(path);
di.Create();
di.Attributes = FileAttributes.Normal;
if (di.Exists)
{
System.Threading.Thread.Sleep(1000);
System.IO.FileInfo fi = new FileInfo(path + "\
\default.aspx");
if (!fi.Exists)
{
//Create a file to write to.
using (StreamWriter sw = fi.CreateText())
{
sw.WriteLine("Page Not Found.");
}
fi.Attributes = FileAttributes.Normal;
}

}

anyone got any ideas?

Apr 27 '07 #1
6 1765
Hello Charlie,

How much directories do u create? coz afaik framework has a specific limit
(don't remember the exact number) of the directories

---
WBR, Michael Nemtsev [.NET/C# MVP].
My blog: http://spaces.live.com/laflour
Team blog: http://devkids.blogspot.com/

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo

CBhas full access to the file system so it isn't a general permissions
CBthing. the securiy exception occurs on the last file or direcotory
CBcreated.
CBthe last file or directory it creates before the exception is throw
CBis
CBnormally inaccessible and will be locked. i won't be able to delete
CBit
CBmanually in explorer - it will say i don't have permission even if i
CBam the administrator. i won't even be able to view the security info
CBor anything about it. After a while the file or folder will
CBdisappear
CBor become deletable.
Apr 27 '07 #2
Are you asking why you might not have access or what do do about it?

You may get access denied if the directory a sub-directory or file within
that hierarchy is in use ("current directory" setting constitutes a directory
in use). You'll have to handle these exceptions properly, there's nothing
you can do if another program is using these files/directories (like a defrag
program or a virus checker).

As to what to do about it; that's really up to your application. You must
handle these exceptions if you don't want to take down the current session.

--
Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
http://www.peterRitchie.com/blog/
Microsoft MVP, Visual Developer - Visual C#
"Charlie Bear" wrote:
i'm really stuck with this one can anyone help!

i have a website that uses c#. it creates a series of directories and
files from an xml source. when the xml changes, the directory that the
change applies to is deleted and recreated. All the children for that
directory are also re created (as the parent directory then has a
different name).

the problem i have is that *sometimes* the files or directories don't
get created. It either gets stuck creating the file or the directory.
i get either an io exception or a security exception. the .net runtime
has full access to the file system so it isn't a general permissions
thing. the securiy exception occurs on the last file or direcotory
created.
the last file or directory it creates before the exception is throw is
normally inaccessible and will be locked. i won't be able to delete it
manually in explorer - it will say i don't have permission even if i
am the administrator. i won't even be able to view the security info
or anything about it. After a while the file or folder will disappear
or become deletable.

No one else is using these files since it is on my test machine so it
can't be because of that.

the code i am using to create the direcotory and file is as follows.
this is run in a for loop - each xml node has directory name which
forms the path:

System.IO.DirectoryInfo di = new
DirectoryInfo(path);
di.Create();
di.Attributes = FileAttributes.Normal;
if (di.Exists)
{
System.Threading.Thread.Sleep(1000);
System.IO.FileInfo fi = new FileInfo(path + "\
\default.aspx");
if (!fi.Exists)
{
//Create a file to write to.
using (StreamWriter sw = fi.CreateText())
{
sw.WriteLine("Page Not Found.");
}
fi.Attributes = FileAttributes.Normal;
}

}

anyone got any ideas?

Apr 27 '07 #3

i'm asking what to do about it!

it can happen when i'm creating one folder with a file or lots.

So are you saying that a directory could be locked by a virus scan
which in turn prevents the system creating a file / directory in it?

surely i should always be able to open a directory in explorer - which
is what i can't do after it's gone wrong. it doens't even have any
permissions or an owner. it's like it's half created

i handle the exception at the moment but i can't do anything with the
direcotry that has gone wrong for several mins afterwards which means
the application can't just try again.

is there something i can do to prevent this occuring. like slowing
down the creation of the files by adding a long thread.sleep or is
there a less intensive way of creating files?
Apr 27 '07 #4
hi,
Use

sw.Flush();
sw.Close();

inside the using loop.
-
shashank kadge.

On Apr 27, 9:36 am, Charlie Bear <char...@contrapositive.tvwrote:
i'm really stuck with this one can anyone help!

i have a website that uses c#. it creates a series of directories and
files from an xml source. when the xml changes, the directory that the
change applies to is deleted and recreated. All the children for that
directory are also re created (as the parent directory then has a
different name).

the problem i have is that *sometimes* the files or directories don't
get created. It either gets stuck creating the file or the directory.
i get either an io exception or a security exception. the .net runtime
has full access to the file system so it isn't a general permissions
thing. the securiy exception occurs on the last file or direcotory
created.
the last file or directory it creates before the exception is throw is
normally inaccessible and will be locked. i won't be able to delete it
manually in explorer - it will say i don't have permission even if i
am the administrator. i won't even be able to view the security info
or anything about it. After a while the file or folder will disappear
or become deletable.

No one else is using these files since it is on my test machine so it
can't be because of that.

the code i am using to create the direcotory and file is as follows.
this is run in a for loop - each xml node has directory name which
forms the path:

System.IO.DirectoryInfo di = new
DirectoryInfo(path);
di.Create();
di.Attributes = FileAttributes.Normal;
if (di.Exists)
{
System.Threading.Thread.Sleep(1000);
System.IO.FileInfo fi = new FileInfo(path + "\
\default.aspx");
if (!fi.Exists)
{
//Create a file to write to.
using (StreamWriter sw = fi.CreateText())
{
sw.WriteLine("Page Not Found.");
}
fi.Attributes = FileAttributes.Normal;
}

}

anyone got any ideas?

Apr 27 '07 #5
On Apr 27, 10:59 am, Charlie Bear <char...@contrapositive.tvwrote:
i'm asking what to do about it!

it can happen when i'm creating one folder with a file or lots.

So are you saying that a directory could be locked by a virus scan
which in turn prevents the system creating a file / directory in it?

surely i should always be able to open a directory in explorer - which
is what i can't do after it's gone wrong. it doens't even have any
permissions or an owner. it's like it's half created

i handle the exception at the moment but i can't do anything with the
direcotry that has gone wrong for several mins afterwards which means
the application can't just try again.

is there something i can do to prevent this occuring. like slowing
down the creation of the files by adding a long thread.sleep or is
there a less intensive way of creating files?

Try

sw.Flush();
sw.Close();

just before the 'using' loop ends.

-
shashank kadge

Apr 27 '07 #6
turning off my servers auto protect virus guard on the website
directory seems to have reduced the problem significantly. it still
occurs but when i retry it it works. i've got a try and catch around
the creation which will stop the process and alert the user to try
again.i've also added the "flush" and "close" just to be sure even
though its in a using block.

thanks for all your help guys...


Apr 27 '07 #7

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

Similar topics

3
by: dave | last post by:
I am using vs.net 2003 on windows xp. After clicking on a project within my solution and selecting create new folder vs.net responds back with , the "directory already exists". If i look at the...
6
by: Ferrari, Eduardo | last post by:
Hi all! I'm trying to create this XML file: <?xml version="1.0" encoding="utf-8" ?> <Build type="Daily" sync="True" compile="True" assemble="True" > <Sync version="1.0.0.0" branch="QA">...
6
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...
1
by: Senthil | last post by:
Con is the file name for a reserved device name(i think it is for console). So you cannot create a file with name 'con'. choose some other name senthil >-----Original Message----- >Hi...
0
by: Luther Hert | last post by:
I solved my problem, but I am not sure whether or not I understand how I arrived at the solution. I leraned about and checked: IIS> creating virtual directories> configuring web extensions >...
3
by: Wilson | last post by:
i am very new to c++ and am creating a new program, below are two seperate parts of the program, made to run seperately, however the constructor in one works (prints "constructing" on the screen),...
10
by: Gotch | last post by:
Hi all, I've installed the CDT plugin for Eclipse and I want to use it to work on C/C++ projects under Cygwin. It works, in fact it compiles and runs the usual helloworld c++ program. Now it comes...
7
by: Yansky | last post by:
I asked my hosting company if they would upgrade Python on my server to the latest version. They responded with: "Sorry no. We tend to stick with what comes packaged with the unix distribution...
19
by: Ant | last post by:
Hi all, I have a question on PyParsing. I am trying to create a parser for a hierarchical todo list format, but have hit a stumbling block. I have parsers for the header of the list (title and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
jinu1996
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.