A file or folder with the name already exists Visual Studio

Visual Studio

Visual Studio Problem Overview


I try to add a new file to my source controlled solution and receive this message:

> A file or folder with the name 'xxx' already exists. Please give a unique > name to the item you are adding, or delete the existing item first.

I'm 100% sure that there is no file with the given name.

So how do I get VS to add items again?

Visual Studio Solutions


Solution 1 - Visual Studio

Restarting Visual Studio didn't help, the folder is cached on the system.

Open Solution Explorer there is an icon that looks like a many Pages: Show All Files which is the Show All Files. Once clicked, one is able to see the hidden, to the visual studio project, the folder that was causing this error. (Look for the folder in the View section.)

After I deleted the unwanted folder, and Rebuild Project, You should be able to Create the controller which will create the view automatically...

Solution 2 - Visual Studio

Restarting Visual Studio helped me.

Solution 3 - Visual Studio

Steps if a folder is Missing

  1. In the Solution Explorer window
    • Select visual studio project which holds the missing folder.
    • Select or turn on the Show All Files button ( Show All Files ) to show the existing, but missing folder.
  2. Select the hidden folder then right click and select the menu item Include in Project to add into the project in the project view.

Solution 4 - Visual Studio

Simply, On Solution Explorer Right CLick on Project's name -> Unload Project. then right click on the same project and click 'Reload'.

Problem is Fixed (y)

Solution 5 - Visual Studio

If you're using MVC, and trying to create a new Controller, you should also check the Views and Models. Even though there was no folder or file with the Controller name, I had to delete a View folder with the same name (that already existed for some reason) using Show All Files and rebuild the solution.

Solution 6 - Visual Studio

I fixed it by actually adding a file and then deleting it again.

Solution 7 - Visual Studio

The project file was unloaded in visual studio 2017

image

The easiest way is to copy your project folder and paste different repository then open your project in visual studio then after run the project, it should work. for example (D:--------->E:[here i mentioned repository these things])

Solution 8 - Visual Studio

Visual Studio 2017 v 15.9.12 ... I ran into this problem, but with no actual folder conflict. In my case, I had solution folder named NewOrder, and I was trying to create a child project with the same name, but encountered the above error. I tried closing and reopening the solution (didn't restart VS so not sure if that would have made a difference) but here's what worked for me.

  • renamed solution folder
  • created my project. At this point, I got a strange error about not being able to locate the .net standard 2.0... so then I did restart VS, which fixed that problem
  • renamed the folder back

Now everything works fine. I restarted VS again just for good measure and all works fine now.

Solution 9 - Visual Studio

In my case, when trying to add a new project to a solution, even though a project with the same name had been removed from the solution in visual studio (2019), I had to open file explorer and delete the folder for the removed project.

Solution 10 - Visual Studio

I right clicked and removed folder. Then Clicked upper the folder I wanted to create project in and created project. In the Location section I opened the File explorer and the file I had deleted still appeared -> deleted it from here and then went ahead.

enter image description here

Solution 11 - Visual Studio

Click on Show All Files Menu in Solution Explorer and See That file in Controller, Views and Model Folder and delete that from there also

Solution 12 - Visual Studio

You need to give attention if adding a file automatically add other files/folders..for example if I added a controller which automatically add folder with controller name in views..I couldn't add controller .cs file until I deleted folder with controller name from views.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRuudtView Question on Stackoverflow
Solution 1 - Visual StudiomisterzikView Answer on Stackoverflow
Solution 2 - Visual StudioniaherView Answer on Stackoverflow
Solution 3 - Visual StudioΩmegaManView Answer on Stackoverflow
Solution 4 - Visual StudioMa3d Alsha3bieView Answer on Stackoverflow
Solution 5 - Visual StudioAlexandre PaivaView Answer on Stackoverflow
Solution 6 - Visual Studioyakov72View Answer on Stackoverflow
Solution 7 - Visual StudioNiroshan KumarasamyView Answer on Stackoverflow
Solution 8 - Visual Studioebol2000View Answer on Stackoverflow
Solution 9 - Visual StudioamartinView Answer on Stackoverflow
Solution 10 - Visual StudioAfshin GhaziView Answer on Stackoverflow
Solution 11 - Visual StudioNaeem AhmedView Answer on Stackoverflow
Solution 12 - Visual StudioViorelView Answer on Stackoverflow