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))


Where is the server located in relation to your dev machine? On the same machine? Same LAN?

It is a Microsoft Windows Server 2008 R2 and it located on a actual server. I am connecting to it remotely.

On the same LAN? Can you connect via your browser? What port is it using?

Yes I am on the same LAN and using the port :34146.

If I type this into my browser the sharepoint site loads correctly, but if is use it in my code it does not work.