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?