blog.dennus.net A reflection on Microsoft Office SharePoint Server 2007 (and other stuff…)

13Jul/100

SharePoint 2010 Console Application Quirks

So, in order to get the schema XML of some field I've created on my SharePoint 2010 site, I decided to write a quick console application to retrieve the data.I quickly discovered that apparently some things have changed regarding how to use a console application with SP2010. I figured the code would pretty much be the same as it was in 2007:

const string siteUrl = "http://spfoundation/sites/testsite";

using (SPSite site = new SPSite(siteUrl))
{
   using (SPWeb web = site.OpenWeb())
   {
      SPList list = web.Lists["Test"];
      SPField field = list.Fields["Languages"];

Console.WriteLine(field.SchemaXml);
   }
}

Running this code however, quickly resulted in an error:

The Web application at http://spfoundation/sites/testsite could not be found.

Surely I didn't make a typo, as I copied the URL from the browser and it works over there. After some looking around for what to do, I figured out there are a couple of things you need to change:

  • You need to run Visual Studio 2010 as an administrator.*
  • The target framework of your application needs to be ".NET Framework 3.5"
  • Because SP2010 is a 64-bit application, the platform target of your application needs to be 64-bit as well. The setting "Any CPU" seems to be working as well.

(*) I installed SP2010 on a workstation running on Windows 7 Professional, so this requirement may be different for scenarios where your Visual Studio is running on a server with SP2010.

Share and Enjoy:
  • StumbleUpon
  • Print
  • del.icio.us
  • Facebook
  • Twitter
  • Digg
  • Sphinn
  • Google Bookmarks
Filed under: SP2010 Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


No trackbacks yet.