Friday, June 27, 2008

The specified name is already in use.

If the above error looks familiar and you can't seem to get rid of it, then read on, I might have a solution for you then!

When trying to activate a feature that would create a list, I received the following error:

The specified name is already in use.

A list, survey, discussion board, or document library cannot have the same name as another list, survey, discussion board, or document library in this Web site.
Use your browser's Back button, and type a new name.


The biggest problem was that the list really didn't exist. When I went to "All Site Content", nothing was there with the name of the list I was creating. I also looped over all my lists with three lines of code I quickly wrote, but nothing there either... After some searching on our good friend Google, I learned that apparently, if you open the site with SharePoint Designer, there is a folder there with that name. Just delete the folder and everything works fine again...

But what if you don't have SharePoint Designer installed and you can't intall it immediately, like me? Well, then these few lines of code might help you out:

SPSite site = null;
SPWeb web = null;

using (site = new SPSite(siteURL))
{
    using (web = site.OpenWeb())
    {
        web.Folders[nameOfListToCreate].Delete();
    }
}

No comments: