0

I have a .aspx page and a .aspx.cs page. These were created in VS. I've copied the solution folder to SharePoint using SPD. When browsing the page I get an error

Parser Error Message: The codefile attribute on the page directive is not allowed in this page. I've looked around on the web and found 3 possible ways. The first seems over-complex. Are options 2 or 3 possible. Have tried oprion 2 but doesnt appear to work.

  1. Ive seeen Andrew Connells blog: http://www.andrewconnell.com/blog/articles/UsingCodeBehindFilesInSharePointSites.aspx

  2. I've seen another article referring to changing the web.config file to run the code behind:

  3. Is it possible to use inheritance instead? http://social.technet.microsoft.com/Forums/en-US/sharepointdevelopmentlegacy/thread/87604ae8-72eb-404f-9ea1-2692038f36f5

Hope someone can help on this.

4
  • The problem is, that the assemblies (dll's) are not in the bin folder. So it's not compiled, see davids answer) But why didn't you create a webpart? It supports coded visual webparts (on farm solutions).
    – Sascha
    Commented Apr 24, 2013 at 13:06
  • what you actually trying to do ? Commented Apr 24, 2013 at 13:32
  • We need to display sql results of another system on a SP page. The page has a gridview. Code exists in VS and contains files (default.aspx, Default.aspx.cs , data.cs and .sql) code-behind and a class. Main purpose is to show status of external system. I added the entire folder into a new web using SPD (All Files) sp20104/alerts/EmailAlerts Possible to browse location and this is where error reported. I’ve tried looking for the physical files but cannot find them. Have they been serialised to database? cont.. Commented Apr 25, 2013 at 7:41
  • Despite not finding files is it best to create a webpart , wsp or application page. If yes how can I do this with the existing VS project? Commented Apr 25, 2013 at 7:42

2 Answers 2

1

The issue is that you're copying the ASPX and the ASPX.CS file into SharePoint, which I don't believe is supported. You need to compile the project, and deploy it ideally via a WSP solution, but you could copy the DLL and the ASPX (not the .cs) manually.

I'd bet that your issue is a limitation around security, which would deny people easy code access to a farm.

As far as the masterpage is concerned, you can get away without using one, and just use your own ASPX page standalone.

HTH

13
  • Hi From the anwers above are there multiple ways in achieving my requirements? i.e. Application page, Web Part? You mention the limitation in security, can I override this? Someone else produced this and gave me the project files. In VS shall I build and copy DLL to SharePoint ? Commented Apr 24, 2013 at 13:21
  • It all depends on your requirements. To @Sascha's point, you could build the project in VS, then copy the DLL to the web application's BIN directory. That should allow your ASPX pages to run. The code will run within the SP application pool, but permissions are restricted via the web.config file. Commented Apr 24, 2013 at 13:27
  • In the end, you will have to compile the project, you can't run uncompiled code in SharePoint. Commented Apr 24, 2013 at 13:28
  • Additionally, check out msdn.microsoft.com/en-us/library/ff798412.aspx for more around SP's execution models. Commented Apr 24, 2013 at 13:31
  • Is this similiar to option 1 that I've mentioned in my question? Commented Apr 24, 2013 at 13:32
2

you can create an applicationpage

An application page is an ASP.NET Web page that is designed for use in a SharePoint Web site. Application pages are a specialized type of ASP.NET page. The primary difference between an application page and a standard ASP.NET page is that an application page contains content that is merged with a SharePoint master page. A master page enables application pages to share the same appearance and behavior as other pages on a site.

Visual Studio enables you to design application pages by using a designer. The designer displays a content area for each content placeholder that is defined in a master page. You can design the application page by dragging controls to these content areas.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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