2

I have been trying to get my MVC C# code to connect to my sharepoint server. I have tried everything and I keep getting this error no matter what I try.

The Web application at [http://myserver/] could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application.

This is my code:

string strUrl = "http://myserver/";
using (SPSite site = new SPSite(strUrl))
{
}
tereško
  • 58,060
  • 25
  • 98
  • 150

3 Answers3

4

Note that SPSite/SPWeb only work on a Server that has SharePoint installed and is part of the Farm. It may work on non-Sharepoint machines, but this is officially unsupported and certain operations may throw exceptions.

Generally, external connectivity to SharePoint is done through Web Services or (since 2010) through the Client Object Model.

Michael Stum
  • 177,530
  • 117
  • 400
  • 535
0

Use the Client Object Model to connect (assuming you are using SharePoint 2010). If you want to use the server object model (which you are using in your code sample), the MVC app will need to be running on the same server that SharePoint is running on.

Kyle Trauberman
  • 25,414
  • 13
  • 85
  • 121
0

Make sure that you target your binary as 64-bit with .Net framework 3.5, otherwise it will throw this error. Also as other answers has stated; to use the object model like this require that the code is executed on a server in the farm.

Rikard Uppström
  • 1,413
  • 9
  • 16
  • I have tried to use .NET 3.5 and set the target as 64-bit, but when I do I get a bunch of errors and I cannot compile. Also, I am running my code on the server that way I can use the server object model. None of these fixes will fix my problem. – 44 6f 6f 20 44 6f 6f Jun 06 '12 at 18:28
  • Ok, but until you manage to compile and run your code 64-bit, 3.5, your error will continue. What kind of error are you getting when trying to compile? – Rikard Uppström Jun 07 '12 at 07:01
  • Some of the dll's cannot compile to 64bit. – 44 6f 6f 20 44 6f 6f Jun 08 '12 at 19:48