Compartilhar via


How to: Add Files to ASP.NET Web Projects in Visual Studio

You can add new and existing files to an ASP.NET Web project. Some file types can only exist in special ASP.NET subdirectories. For example, browser definition files (.browser) can only be created in the App_Browsers application subdirectory. If you attempt to create a browser definition file in the root of your application, Visual Studio will give you the option to put it in the App_Browsers subdirectory. For a list of file types, see ASP.NET Web Project File Types. For details about creating special ASP.NET folders, see the subsequent procedure.

Web site projects in Visual Studio are directory based. When you open a Web site, Visual Studio treats all of the files in the folder that you open — whether the files are in the file system, in an Internet Information Services (IIS) application, or on an FTP site — as part of the same Web site. Web application projects keep track of which files are included or excluded from the project in a project file. For more information, see Web Application Projects versus Web Site Projects in Visual Studio.

To add a file to an ASP.NET Web site

  1. In Solution Explorer, right-click the Web site project name, and then click Add New Item.

  2. In the Add New Item dialog box, select the file type that you want to add.

  3. If the Language list is enabled for the file type that you are adding, select the name of the programming language that you want to use for the file.

    Note

    You can create files (pages) with different programming languages in the same Web site project, but typically not in the same Web application project. For more information, see Web Application Projects versus Web Site Projects in Visual Studio.

  4. If you want the code for the page to be in a separate file, be sure the Place code in separate file check box is selected. if you want to keep the code and markup in the same file, clear this check box.

  5. In the Name box, type a name for the file, and then click Add.

    The new file is created and displayed in Visual Studio in the Source view window.

To create a special ASP.NET subdirectory

  1. In Solution Explorer, right-click the project name, and then click Add ASP.NET Folder.

  2. In the list of available folders, click the name of the folder that you want to create.

    For information about special ASP.NET folders, see ASP.NET Web Project Folder Structure.

To add an existing Web page to a Web site project

  1. In Solution Explorer, right-click the project name, and then click Add Existing Item.

  2. In the Add Existing Item dialog box, navigate to the directory that contains the Web page that you want to add, select the page, and then click Open.

    The Web page is added to the project.

    Note

    When you add an existing file, the file is copied to your project, not added by reference. Thus, if you change the file in your project, the original file is left unchanged.

To change the name of a Web page using Solution Explorer

  1. In Solution Explorer, right-click the file name that you want to change and then click Rename.

  2. Type the new file name that you want and then press ENTER.

    Note

    If the code for the page is in a separate file, Visual Studio automatically renames the code file as well and changes the @ Page directive in the .aspx page to match the renamed code file.

See Also

Concepts

ASP.NET Web Project File Types

Other Resources

ASP.NET Web Projects

Web Pages and Projects

Visual Studio Solutions and Web Project Source Control

Web Application Projects versus Web Site Projects in Visual Studio