The file name you specified could not be used. It may be the name of an existing file or directory

Posted: April 7, 2012 in Uncategorized
Tags: ,

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.

Really weird!

The fix:
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.

About these ads

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s