2011-10-04 56 views
2

的文件复制到虚拟路径,我动态加载的用户控件像下面我如何在运行时

UserControl objUserControl = (UserControl)this.LoadControl("~/UserControls/ucProfileViewDefault.ascx"); 

现在我有一个位于其他位置的其他用户控件文件ucProfileViewSMSIS.ascx。我需要在运行时将此文件复制到我的虚拟路径,然后像下面那样加载它

UserControl objUserControl = (UserControl)this.LoadControl("~/UserControls/ucProfileViewSMSIS.ascx"); 

我该如何做?

回答

2

Server.MapPathPage.ResloveUrl会得到你的位置,那么你可以将它和负载:

var path = Server.MapPath(Page.ResolveUrl("~/UserControls/ucProfileViewSMSIS.ascx"));