How to Add Reference for Microsoft.Sharepoint to a Web-Application
-
09-12-2019 - |
Question
Salve! Having created a web-application under the Sharepoint (2010) Site's directory in iis7, I now need to use the assemble microsoft.sharepoint in my web-application. How can I reference that?
I can confirm that the reference is being inherited from the parent's (sp) web.config, because if I add the reference, asp.net complains that there is a duplicate entry.
What can I do?
Solution
My recommendation would be that you shouldn't.
You should start from scratch again and develop your Web-Application to be deployed below the _layouts folder in SharePoint using a WSP package and all of your code should be in code behind which is compiled into a dll deployed to the GAC.
You can technically get your solution to work, but it's a hack, that won't work when an extra server is added.
OTHER TIPS
Add the SharePoint.dll as a reference in your project: \Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI\Microsoft.SharePoint.dll
I assume this is SharePoint 2010.
This seems to work: copy the microsoft.sharepoint.dll from the directory indicated above, by Kolten (\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI\Microsoft.SharePoint.dll) and put it in the bin folder of your web-application. Now you can add using microsoft.sharepoint
to your code-behind and not get an error page.
Here is a relevant thread: https://stackoverflow.com/questions/1629245/microsoft-sharepoint-and-microsoft-office-namespace-issue
I post this here because it is, indeed, an answer, and it does work. However, I think Mr. Jakobsen's answer is better.