Fix for Not able to connect to SharePoint 2010 server web sites through Visual Studio 2010

Today, I started working on SharePoint 2010 server side object model to delete all the files from the document library using batch command. I have written all the code but, I failed to connect to the web site using SPSite class. I tried all combination like with server name, ip address and many more. Always I am getting the exception that "not able to connect to SharePoint site".
This is the actual exception :
"The Web application at http://nb16 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."

Below figure gives you complete details.
Below is the code [Console application] I have used to communicate with the sharepoint server.
class Program
{
static void Main(string[] args)
{
DeleteAllItemsUsingBatch();
}
private static void DeleteAllItemsUsingBatch()
{
using (SPSite site = new SPSite("http://nb16"))
{
SPWeb web = site.OpenWeb("/");
SPList list = web.Lists["Documents"];
StringBuilder sb = new StringBuilder();
sb.Append("");
string batchCommand = "<method><setlist scope=\"Request\">" + list.ID + "</setlist><setvar name=\"ID\">{0}</setvar><setvar name=\"Cmd\">DELETE</setvar><setvar name=\"owsfileref\">{1}</setvar></method>";
foreach (SPListItem item in list.Items)
{
sb.AppendFormat(batchCommand, item.ID.ToString(), item.File.ServerRelativeUrl);
}
sb.Append("
");

web.AllowUnsafeUpdates = true;
site.RootWeb.ProcessBatchData(sb.ToString());
web.AllowUnsafeUpdates = false;
web.Close();
}
}
}

Did you find any problem with the code? Not really. There are no problems with the code at all.. Then what's wrong?
When I researched on the net for the solutions I found below information.
1. Is SharePoint site running?
2. Did you develop code on the same SharePoint server?

But, everything fine. There are no issues. Then what was the problem? I was frustrated for 3 hours to find the solution.
Solution:
It's simple that the platform target in build options was set to the x86 format by default. It should be set to x64 to work correct.
So, sometimes the simple problems will take more time to fix. Enjoy the nice series of posts on SharePoint 2010.

0 komentar:

Post a Comment

Related Posts with Thumbnails
GiF Pictures, Images and Photos