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.


Comments

Dec 09 Marcin

Marcin

In visual studio gallery there is a very useful template for  sharepoint console application visualstudiogallery.msdn.microsoft.com/.../7909f63a-41b9-45f7-a758-eb2aa43e6907
Enjoy!

May 09 OMF

OMF

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...  >:[

May 27 George

George

how can i do the same change to x64 in ASP.NET Applicaiton?

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading





Creative Commons License
Chaks' Corner Blog by Chakkaradeep Chandran is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.
Based on a work at www.chakkaradeep.com.
Permissions beyond the scope of this license may be available at http://www.chakkaradeep.com.