How To: Change the Dynamic Data Folder Location

The default location for Dynamic Data files is in the root folder of the Web application. Some Web applications might require that you move the Dynamic Data files to another directory location.

This topic describes how to move the location of the Dynamic Data files in an existing Dynamic Data Web application. For more information about how to add Dynamic Data to an existing Web site, see How To: Add Dynamic Data to an Existing Web Site.

To change the Dynamic Data files location

  1. In the Web site, create a new folder and move the contents of the DynamicData folder to the new location.

    For example, at the root level of the Web application, create a folder named AdminTools and move the DynamicData folder as a subfolder to the AdminTools folder.

  2. Open the Global.asax file.

  3. In code, set the DynamicDataFolderVirtualPath property of the MetaModel class to the new path. You typically do this in the method that is used to register routes.

    The following example shows how to set the DynamicDataFolderVirtualPath property to "~/AdminTools/DynamicData".

    <%@ Application Language="C#" %>
    <%@ Import Namespace="System.Web.Routing" %>
    <%@ Import Namespace="System.Web.DynamicData" %>
    
    <script runat="server">
    public static void RegisterRoutes(RouteCollection routes) {
        MetaModel model = new MetaModel();
        model.RegisterContext(typeof(AdventureWorksLT2008Model.AdventureWorksLT2008Entities), 
            new ContextConfiguration() { ScaffoldAllTables = true });
    
            model.DynamicDataFolderVirtualPath = "~/AdminTools/DynamicData";
    
            routes.Add(new DynamicDataRoute("{table}/{action}.aspx") {
                Constraints = new RouteValueDictionary(new { action = "List|Details|Edit|Insert" }),
                Model = model
        });
    }
    
    void Application_Start(object sender, EventArgs e) {
        RegisterRoutes(RouteTable.Routes);
    }
    </script>
    
    <%@ Application Language="VB" %>
    <%@ Import Namespace="System.Web.Routing" %>
    <%@ Import Namespace="System.Web.DynamicData" %>
    
    <script RunAt="server">
        Public Shared Sub RegisterRoutes(ByVal routes As RouteCollection)
            Dim model As New MetaModel
    
            model.RegisterContext(GetType(AdventureWorksLT2008Model.AdventureWorksLT2008Entities), _
                                  New ContextConfiguration() With {.ScaffoldAllTables = True})
    
            model.DynamicDataFolderVirtualPath = "~/AdminTools/DynamicData"
    
            routes.Add(New DynamicDataRoute("{table}/{action}.aspx") With { _
                .Constraints = New RouteValueDictionary(New With {.Action = "List|Details|Edit|Insert"}), _
                .Model = model})
        End Sub
    
        Private Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
            RegisterRoutes(RouteTable.Routes)
        End Sub
    
    </script>
    
  4. Save and close the Global.asax file.

  5. Open the List.aspx and ListDetails.aspx files.

  6. In the @ Register directive for the GridViewPager and FilterUserControl controls, change the src attribute to reflect the new path location.

    The following example shows the @ Register directive for a page in an application where the DynamicData folder has been moved to the AdminTools folder.

    <%@ Register src="~/AdminTools/DynamicData/Content/GridViewPager.ascx" 
        tagname="GridViewPager" tagprefix="asp" %>
    <%@ Register src="~/AdminTools/DynamicData/Content/FilterUserControl.ascx" 
        tagname="DynamicFilter" tagprefix="asp" %>
    
  7. Open the List.aspx file.

  8. In the img element, change the src attribute to reflect the new path location, as shown in the following example:

    <div class="bottomhyperlink">
      <asp:HyperLink ID="InsertHyperLink" runat="server">
      <img runat="server" 
           src="~/AdminTools/DynamicData/Content/Images/plus.gif" 
           alt="Insert new item" />
        Insert new item
      </asp:HyperLink>
    </div>
    

See Also

Tasks

How To: Add Dynamic Data to an Existing Web Site

Change History

Date

History

Reason

July 2008

Added topic for new class.

SP1 feature change.