SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a Webpart with a "main class" named myClass

public class myClass : Microsoft.SharePoint.WebPartPages.WebPart

and I want to load a ascx file from this class like this

but when I trying to do this:

 Control c = Page.LoadControl("~/myAscx.ascx");


 Control c = Page.LoadControl("~/nameWebpart/myAscx.ascx");

I only get the message:

"The file myAscx.ascx does not exist"

The file myAscx is in the same "folder" of the myClass. How can I know the correct path?

share|improve this question
up vote 1 down vote accepted

You can place Your ascx in the layouts folder C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\ and then

MyClass c = (MyClass)Page.LoadControl("/_layouts/MyAscx.ascx");

Of course You can also create a subfolder under the LAYOUTS directory and update the LoadControl path accordingly.

share|improve this answer
It works fine ^^ – user674887 Aug 23 '11 at 11:58

ascx files are stored in the COntrolTemplates folder in the 14 hive of sharepoint.

So it's path will be something like:

private const string _ascxPath = @"~/_CONTROLTEMPLATES/ProjectFolder/controlname.ascx";
share|improve this answer
Thanks, but this was a custom ascx that places in another folder. Maybe the controltemplates is only for default ascx – user674887 Aug 23 '11 at 11:57
the _controltemplates can be substituted with whatever location under the 14 hive you want (_layouts, _vti_bin (ISAPI) etc. etc.) – Colin Aug 24 '11 at 6:44

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.