Thursday, December 16, 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://spportal:90"))
            {
                using (SPWeb spWeb = spSite.RootWeb)
                {
                    Console.WriteLine(spWeb.Title);
                }
            }
 
            Console.WriteLine("Done!");
        }
    }
}


If you build the same code, execute it against SharePoint 2010, you will be surprised  to see VS2010 throw an error! "File not Found Exception......."


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. The other thing to make sure is that the target framework is .NET 3.5.

No comments:

Post a Comment