Ruudt
Ruudt

Reputation: 870

A file or folder with the name already exists Visual Studio

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?

Upvotes: 71

Views: 81103

Answers (13)

Axeltherabbit
Axeltherabbit

Reputation: 746

I just had a tab open with the file name, closing it solved the issue for me

Upvotes: 0

Afshin Ghazi
Afshin Ghazi

Reputation: 2990

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

Upvotes: 3

ΩmegaMan
ΩmegaMan

Reputation: 31686

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.

Upvotes: 19

amartin
amartin

Reputation: 350

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.

Upvotes: 0

Naeem Ahmed
Naeem Ahmed

Reputation: 276

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

Upvotes: -2

Alexandre Paiva
Alexandre Paiva

Reputation: 304

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.

Upvotes: 10

ebol2000
ebol2000

Reputation: 1283

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.

Upvotes: 0

Niroshan Kumarasamy
Niroshan Kumarasamy

Reputation: 55

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])

Upvotes: 0

Viorel
Viorel

Reputation: 33

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.

Upvotes: -4

Ma3d Alsha3bie
Ma3d Alsha3bie

Reputation: 141

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)

Upvotes: 13

yakov72
yakov72

Reputation: 21

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

Upvotes: 1

misterzik
misterzik

Reputation: 1880

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...

Upvotes: 117

g45rg34d
g45rg34d

Reputation: 9660

Restarting Visual Studio helped me.

Upvotes: 22

Related Questions