Welcome to deBUG.to Community where you can ask questions and receive answers from Microsoft MVPs and other experts in our community.
0 like 0 dislike
21 views
in SharePoint Server by 7 8 11

In SharePoint 2019 solution, I have the below code that loads a "user control.ascx" to a normal SharePoint web part

this._pager = (HTMLPager)this.Page.LoadControl(@"~/_controltemplates/Emp/EpmPager.ascx");
base.CreateChildControls();
this.Controls.Add(this._pager);

I perform built and deploy for this solution with no errors, but when I add the web part to a page I got this error The file 'UserControl.ascx' does not exist 

 The file '/_ControlTemplates/Emp/Emp.ascx' does not exist.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: The file '/_ControlTemplates/Emp/Emp.ascx' does not exist.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[HttpException (0x80004005): The file '/_ControlTemplates/Emp/Emp.ascx' does not exist.]
   System.Web.UI.Util.CheckVirtualFileExists(VirtualPath virtualPath) +162
   System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate) +146
   System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate) +131
   System.Web.Compilation.BuildManager.GetVPathBuildResult(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean ensureIsUpToDate) +71
   System.Web.UI.TemplateControl.LoadControl(VirtualPath virtualPath) +78
   CQWPWithPager.WebPartCode.WebPart1.WebPart1.CreateChildControls() +163
   System.Web.UI.Control.EnsureChildControls() +130
   System.Web.UI.Control.PreRenderRecursiveInternal() +66
   System.Web.UI.Control.PreRenderRecursiveInternal() +276
   System.Web.UI.Control.PreRenderRecursiveInternal() +276
   System.Web.UI.Control.PreRenderRecursiveInternal() +276
   System.Web.UI.Control.PreRenderRecursiveInternal() +276
   System.Web.UI.Control.PreRenderRecursiveInternal() +276
   System.Web.UI.Control.PreRenderRecursiveInternal() +276
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6881

the file user control.ascx doesn't exist in SharePoint webpart

I am using Visual Studio 2022, How can solve this error?

by 16 25 33
0 0
Are you sure the path of user control is correct?

1 Answer

1 like 0 dislike
by 54 119 241

In SharePoint 2019, and even in older SharePoint versions like SharePoint 2016, and SharePoint 2013, The Control Template folder is located at

C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\TEMPLATE\CONTROLTEMPLATES\

As you can see, the CONTROLTEMPLATE is located under the 15 hives, and to get your code to work, you have to /15/ after /_controltemplates/ as below:

"~/_controltemplates/15/Emp/EpmPager.ascx".

Try now to deploy your solution that would be working properly.

If you don’t ask, the answer is always NO!
...