Monday, February 22, 2010

System.IO.FileNotFound exception in SharePoint 2010

Hi All,

Just came to know about very basic stuff in SharePoint 2010. Let’s say you are creating one simple console application in VS 2010 that just displays your site name.

using System;
using Microsoft.SharePoint;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
using (SPSite objSiteColl = new SPSite("http://myurl"))
{
Console.WriteLine("Title of the site is : {0}", objSiteColl.RootWeb.Title);
}

Console.ReadLine();
}
}
}



And you run the code, you get System.IO.FileNotFound exception saying that web application is not found, verify that you have typed the correct URL. So what do we do now? We go back and check the URL,hum…URL is perfect, nothing wrong about this. So small program and still not able to run it?

Well, answer lies in VS 2010 because by default build property is set to x86 and SharePoint does not work on x86 platform. As we all know that now MS wants everyone to move on 64 bit PCs. (Another money eating machine), so go to project properties, go to build tab and change the platform target to x64 and try now.

There you go; I think your error might have gone now. What say?

4 comments:

Anonymous said...

What if You Select it as Any CPU

PaulB said...

Thanks for the fix. I linked back to your article. Thanks paul

rajesh said...

I have changed target platform to x64 but still facing the File not found exception

Parth Patel said...

rajesh,

we think it should resolved.

check application log and SP log, you might find something over there.




Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to sharepointkings@gmail.com with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!

If anyone would like to have their advertisement posted on this blog, please send us the requirement details to sharepointkings@gmail.com