The file name you specified could not be used. It may be the name of an existing file or directory
I think this is one of the most weird errors I ever had in SP 2010, it took me about 3 hours to locate the problem and the fix was pretty simple.
In my current environmnet, I have 3 sharepoint solutions, each solution is for different sharepoint templates we have.
In each solution, there are content types, lists, webtemplates, webparts, etc, etc.
When I started to debug the problem, I saw the error was on the following line, where it iterates over all contenttypes for each list.
foreach (SPList list in CurrentWeb.Lists)
SPContentTypeCollection listctc = list.ContentTypes;
foreach (SPContentType ct in listctc)
the line list.ContentTYpes was the one causing the issue, but why? If everything was working fine?
Well, here is the trick!!!
Because I have 3 different solutions, I made a mistake in one of them, I removed one content type from one feature, so when the solution was updated, it was working fine.
Then in the other solution, after I updadted that one, the problem came up.
The cause is that when it iterates over all SpContentTypeCollection for each list, the content type exists in SHarepoint, but the feature definition file does not exist in the feature folder.
I added the content type again in the 1st solution to the feature, recompiled, repackaged, updated the solution and voila. My site is working again.
This was really complcated to solve, as I could not find anywhere on the net with the exact same problem.