0

I have a small question which ends in a big topic. Is it possible - and yes how - to use C# code in a SharePoint 2013 Hosted App?

I tried to have a .asmx file within my project. Then I get this error.

  @"Error 1
        CorrelationId: 9c1ea930-a131-4f5b-bff5-8a1a61fe34d9
        ErrorDetail: There was a problem with activating the app web definition.
        ErrorType: App
        ErrorTypeName: App Related
        ExceptionMessage: Microsoft.SharePoint.SPException: Exception from HRESULT: 0x81070964 ---> System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x81070964

And then I tried a few tutorials like...

http://chuvash.eu/2012/02/13/custom-httphandler-in-sharepoint-for-getting-dynamic-javascript-code/
http://blogs.msdn.com/b/kaevans/archive/2010/08/04/deploying-an-asp-net-httphandler-to-sharepoint-2010.aspx
http://social.technet.microsoft.com/wiki/contents/articles/24194.sharepoint-2013-create-a-custom-wcf-rest-service-hosted-in-sharepoint-and-deployed-in-a-wsp.aspx

But sometimes I didn't understand correctly or sometime I have other problems during compile everything. I had a problem with getting assembly id/name, too. Because there was no compiled DDL File for the project.

What I want in general? A .app file with a SP Hosted App (for SP 2013) which includes a web service for SP Client Object Model.

So I thinking about using the "default.aspx" with CodeBehind. So I could execute scripts "behind" the aspx. But then it couldn't find the assembly... Or there was something else.

Could anyone help me? If you have some ideas you could !please! provide them to me. Thank's!

user47254
  • 31
  • 5

4 Answers4

1

SharePoint hosted Apps doesn't allow server side code to be excuted on the server, this is the whole idea of SharePoint Apps, nothing should be executed in the SharePoint Front End Servers. Unlike Farm solutions, SharePoint Hosted Apps runs on the client and can only access SharePoint resources through a predefined set of services that can be called either using REST or JSOM.

If you need a custom code, you can create a WCF service, deploy it under ISAPI and call it from your App, but this will not be doable in SharePoint online.

As for your question, you can use ASPX pages of course, but you will never put a code behind for it, as these pages are stored in a Pages Library and by design, it is stored in the content DB, so any code execution is denied.

Only aspx pages that are stored on hard disk like the _layouts pages can have a code behind.

Haitham Shaddad
  • 4,336
  • 2
  • 14
  • 19
0

SharePoint App runs in client context. You can create SharePoint App just using JS, HTML, CSS, JSOM. You cannot use C# for App (excluding CSOM, you can use it for creation remote event receiver for example)

If you need to implement some functionality to on-premise version of SharePoint, use traditional server-side solutions, not App.

  • But thats not mostly true... Or? I can use ASPX... Thats not normal HTML/CSS/JS/JSOM/CSOM, too. So why I can't use this then with CodeBehind or something else? :( – user47254 Nov 25 '15 at 09:10
0

It's important to understand the difference between SharePoint-hosted Apps and Provider-hosted Apps:

SharePoint-hosted Apps

SharePoint-hosted apps, or apps where all components are hosted on either an on-premises or Office 365 SharePoint farm. SharePoint-hosted apps are installed on a SharePoint 2013 website, called the host web. They have their resources hosted on an isolated subsite of a host web, called the app web. The App is created using HTML/JavaScript with CSOM or REST calls

Provider hosted apps

Provider-hosted apps for SharePoint include components that are deployed and hosted outside the SharePoint farm. They are installed to the host web, but their remote components are hosted on another server. The App run in a server that is external to SharePoint's. It has its own infrastructure and the Provider is responsible for keeping it running. They allow you to use Server Side code and uses the .NET CSOM.

This image will give you an overview of different Hosting solutions:

Different Hosting Solutions

Visit the following link for more information: https://msdn.microsoft.com/en-us/library/office/fp179887(v=office.15).aspx

S.Dav
  • 2,436
  • 16
  • 22
  • Sounds interesting. Thanks. It not solve the problem :( But maybe there is no solution because of your image exaplaination... :( – user47254 Nov 25 '15 at 18:51
0

The SharePoint Add-in model uses ASPX pages, which can also include ASPX controls. However any methods called are restricted to client-side scripting - i.e. JavaScript and SharePoint's JSOM (JavaScript Object Model), which is a subset of the Client Side Object Model.

Panoone
  • 181
  • 1
  • 7