Access Denied to a Folder created by ASP.NET on Vista

A pretty simple piece of code drove me into hell lately:

  270 if (!System.IO.Directory.Exists(Server.MapPath(“GamePics\\” + CatName + “\\” + URL)))

  271         {

  272             System.IO.Directory.CreateDirectory(Server.MapPath(“GamePics\\” + CatName + “\\” + URL));           

  273         }

Nothing special in fact. However, if you run Windows Vista this could result into a serious problem. The problem only occurs if the folders (in this case) “CatName” and “URL” didn’t exist before. Meaning, ASP.NET creates the CatName folder AND the URL folder in one go.

If that happens, you won’t have any access to the “URL” Folder – meaning the secondly created folder. You will not be able to delete or access it as it doesn’t have an owner and you will not be able to set an owner either.

I was able to get rid of the folder by logging into the Vista Administrator Account (you have to enable it first). I browsed to the location and the folder was already gone by then, maybe a restart will fix this problem, too.

A workaround:

– Never create more than one folder at the same time in one line.
– Create one folder and then make a seperate System.IO.File.Create call to create the second folder.

In my case this didn’t fire up the Access denied problem. I hope this post will help people facing the same weird problem someday.

1 comment so far ↓

#1 Dan on 06.25.07 at 1:40 pm

Thanks for the advice !

Leave a Comment