The Web application at URL could not be found - Sharepoint 2010 C#

Hi

I´m trying to connect to SharePoint 2010 site using C# but I receive this error

"The Web application at URL 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."

My code is

using (SPSite mossSagc = new SPSite("server")) [THIS LINE SEND THE EXCEPTION]
                    {
                        using (SPWeb mossWeb = mossSagc.OpenWeb())
                        {
                            mossWeb.AllowUnsafeUpdates = true;

Open in new window

jbernier_aioAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rainer JeschorCommented:
Hi,
which SharePoint edition are you using? Server or Foundation?
Where do you run this code - on the SharePoint server?
The parameter in the site constructor has to be a valid URL of a site collection - hence you should use the same url as you use in Internet Explorer to open the site.
So if you open the site "https://myintranet.mycompany.com/sites/it/sitepages/home.aspx" then you constructor should be
using (SPSite mossSagc = new SPSite("https://myintranet.mycompany.com/sites/it"))

Open in new window


Second you have to verify that your application is built/running in x64 bit mode and not in 32 bit / x86 mode.

HTH
Rainer
0
jbernier_aioAuthor Commented:
Hi

Thanks.

I´m using SharePoint 2010 Enterprise, I´m running the code in my dev machine not in the server.

I did try compile at x86, x64, Any CPU, using Framework 3.5 but not works.

The address is copied from the browser bar
0
Rainer JeschorCommented:
Hi,
as you use the SharePoint server object model the code has to run on a SharePoint server. For client usage there are dedicated (but limited) client libraries.
Even if you copy all the SharePoint DLLs to your local machine, the code will never run as there are a lots of internal references and COM references - only working on a computer where SharePoint is installed.

Building Any CPU should normally be fine - x86 will never ever work as SharePoint is only x64.
Framework 3.5 is OK.

What is your main target with this code? Perhaps there is the possibility to use the client object model.

HTH
Rainer
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

jbernier_aioAuthor Commented:
Hi Thanks RainerJ

I need to create some list item from a database view, I can't use BDC because I need to manage data after load in the sharepoint, I mean, add new columns, add calculations and some workflows.
0
Rainer JeschorCommented:
Hi,
OK, list items can be created / updated through Managed Client Object Model.

Be patient I will post a sample code and download link in a couple of minutes.

HTH
Rainer
0
Rainer JeschorCommented:
Hi,

so the SharePoint managed Client runtime can be downloaded here:
http://www.microsoft.com/en-us/download/details.aspx?id=21786

Then you have to add two references to your VS project:
Microsoft.SharePoint.Client.dll and
Microsoft.SharePoint.Client.Runtime.dll

(depends on your installation - in my case the DLLs have been here:
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI)

Then add a
using Microsoft.SharePoint.Client;

Open in new window


And you can start.

string siteUrl = "http://dev.rainerj.local/sites/ee";

ClientContext clientContext = new ClientContext(siteUrl);
Microsoft.SharePoint.Client.List spList = clientContext.Web.Lists.GetByTitle("EEReportStatus");

ListItemCreationInformation newItemInfo = new ListItemCreationInformation();
ListItem spListItem = spList.AddItem(newItemInfo);
spListItem["Title"] = "Test from COM";
spListItem["Status"] = "Completed";
spListItem["Sector"] = "Industry";
spListItem.Update();
clientContext.ExecuteQuery(); 

Open in new window


This creates a new item in the list "EEReportStatus" and fills the info into the three columns (where the status is even a choice column).

Good intro to SMCOM:
http://msdn.microsoft.com/en-us/library/ee857094%28v=office.14%29.aspx

And additional pro is that this runs also in x86 build mode :-)
HTH
Rainer
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.