Skip to main content
All docs
V22.1

Move File to Folder

Purpose

Moves a file to a folder that corresponds to the current namespace.

Availability

Available when the caret is in a namespace declaration or file-scoped namespace declaration. The file must be located in a folder whose name is different from the namespace name.

Usage

  1. Place the caret in a namespace declaration or file-scoped namespace declaration (for C# 10):

    using System;
    
    namespace A.B
    {
        class Program        
        {
            static void Main (string[] args) 
            {
                Console.WriteLine("Hello World");
            }
        }
    }
    
  2. Press Ctrl + . or Ctrl + ~ to invoke the Code Actions menu.

  3. Select Move File to Folder: {Folder Name} from the menu.

    menu-item

After execution, this refactoring moves a file to a folder that matches the selected namespace. If the target folder does not exist in the solution, this refactoring creates this folder.

The following screencast shows the “Move Type to Folder” refactoring in action for C#:

screencast

See Also