in SharePoint 2010

SharePoint 2010: Building a SharePoint Console Application

If you are using SharePoint Server 2007 to build a console application, you would do something like this:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using Microsoft.SharePoint;

 

namespace ConsoleApplication

{

    class Program

    {

        static void Main(string[] args)

        {

            using (SPSite spSite = new SPSite("http://demo2010a"))

            {

                using (SPWeb spWeb = spSite.RootWeb)

                {

                    Console.WriteLine(spWeb.Title);

                }

            }

 

            Console.WriteLine("Done!");

        }

    }

}

If you take the same code, execute it against SharePoint 2010, you will be surprised (at least for the first time) to see VS2010 throw an error!

Console Application Error

There is nothing wrong with your code, except that now SharePoint 2010 is 64bit!

You got it right, your SharePoint Server 2007 console application’s target platform would have been x86(32 bit) and you need to change that to x64(64 bit) in the Build configuration of your project.

x64 Platform Target

The other thing to make sure is that the target framework is .NET 3.5.

Write a Comment

Comment

Time limit is exhausted. Please reload the CAPTCHA.

  1. Thank you! You just saved me from spending ANOTHER couple of hours trying to figure out why this code wasn’t working on SP 2010. Between this problem and the "you have to run the SharePoint 2010 PowerShell as Administrator", I’ve just wasted a good chunk of the night… >:[

  2. I have same question as George, I have this working with the Console project but fails on SPSite object everytime when trying to run on ASP.NET application.

  3. I have an issue. I am exposing SharePoint data through a wcf server (asp.net web site). How do I modify the build settings so that I can access SharePoint from web site? (really through asp.net web site which references a business layer).. A bit confused cause based on this information I must built 64 bit but I don’t see those options in web site app?

    thx

  4. Hi,

    Actually I am created a window application to fetch data from database and add the data in the custom list.

    When I am trying to create the object of SPSite It gives the same error.

    "The Web application at http://inkolsaljnj0503/sites/SP2010-Testing/ 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.:

    I have already change the Platform Target to x64 inside Build section of the properties.

    Please give an idea, how to solve this problem?

    Thanks

    Bishwajit