4

I am making a visual web part which is referencing a user control. The code in SharePointProjectItem.spdata is given below.

<ProjectItemFile Source="ExportUserControl.ascx" Target="CONTROLTEMPLATES\VisualWebPartProject\Export\" Type="TemplateFile" />

In my Export.cs file the code is given below.

private const string _ascxPath = @"~/_CONTROLTEMPLATES/VisualWebPartProject/Export/ExportControl.ascx";

protected override void CreateChildControls()
{
      Control control = Page.LoadControl(_ascxPath);     //ERROR LINE
      Controls.Add(control);
}

I am using SharePoint 2013. Problem is it is giving the following error at ERROR LINE above:

Application error when access /PWA/exportplan/Pages/Export.aspx, Error=The file '/_CONTROLTEMPLATES/VisualWebPartProject/Export/ExportUserControl.ascx' does not exist.

I have checked and the user control file exists at following location:

C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\TEMPLATE\CONTROLTEMPLATES\VisualWebPartProject\Export\ExportUserControl.ascx

There are many other web parts in this solution and all have exact same path being used for user controls and they are working fine but not this one. What shall I change in my code to make it work?

I have tried changing _ascxPath to following but no luck.

private const string _ascxPath = @"~/CONTROLTEMPLATES/VisualWebPartProject/Export/ExportControl.ascx";

and

private const string _ascxPath = @"~/CONTROLTEMPLATES/15/VisualWebPartProject/Export/ExportControl.ascx";

Please help.

EDIT
By the way this solution was made for SharePoit 2012 in VS 2010 and I am using VS 2012 in which I have upgraded the solution.

7

Fixed it by using the following code:

private const string _ascxPath = @"~/_CONTROLTEMPLATES/15/VisualWebPartProject/Export/ExportControl.ascx";

Note I just added 15 after CONTROLTEMPLATES.

1

your issue is here:

private const string _ascxPath = @"~/_CONTROLTEMPLATES/VisualWebPartProject/Export/ExportControl.ascx";

but you have this location.... spot the difference:

C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\TEMPLATE\CONTROLTEMPLATES\VisualWebPartProject\Export\ExportUserControl.ascx

your code should be:

private const string _ascxPath = @"~/_CONTROLTEMPLATES/VisualWebPartProject/Export/ExportUserControl.ascx";

....

looks like you changed the file name from ExportControl to ExportUserControl

  • No it's actually ExportControl but when I copied it in Stackoverflow I deleted some names which contain sensitive information so it's just a mistake on my part when typing the question. – Frank Martin Aug 20 '14 at 11:20
  • By the way this solution was made in VS 2010 for SharePoint 2010 and I am using VS 2012 in which I have upgraded the solution. – Frank Martin Aug 20 '14 at 11:58
  • when you say referencing the file do you mean the ascx is not part of the project but your adding it into the visual webpart through code behind? – Ali Jafer Aug 20 '14 at 12:35
  • Fixed it by adding "15" in ascxPath after CONTROLTEMPLATES – Frank Martin Aug 20 '14 at 12:37
0

I had a similar problem and it was related to wrong deployment under "\14" folder, that it's the old layout for Sharepoint 2010 compatibility mode.

I suggest you to deploy and check if your project is correctly comparing under these folders:

[Common Files]\Microsoft Shared\Web Server Extensions\15\TEMPLATE\CONTROLTEMPLATES\[Your Project]
[Common Files]\\Microsoft Shared\Web Server Extensions\15\TEMPLATE\LAYOUTS\[Your Project]
[Common Files]\\Microsoft Shared\Web Server Extensions\15\TEMPLATE\FEATURES\[Your Project]

If you see that they are under \14 you need to find why.

In my case it was the Package.Package wrongly on "14.0"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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