Tutorial :Execute SPDatasource query in Console App?


Is it possible to execute an SPDataSource object query in a console app for testing?


SPDataSource source = new SPDataSource  {      UseInternalName = true,      DataSourceMode = SPDataSourceMode.List,      SelectCommand = "<View/>"  };    source.SelectParameters.Add("WebId", TypeCode.String, "rootweb");  source.SelectParameters.Add("ListName", TypeCode.String, "Contacts");  var c = source.GetView();   var d = c.Select();  

I think the context info is missing but can't figure out how to add it?


I just looked at it in Refelector and it ends up creating a class called SPDataSourceView which depends on SPContext.

I have never been able to creat an SPContext from a console application because of constructors marked as internal.

One option would be to put your class into a Web Service that is deployed to your SharePoint Farm. Then have your console application call this Web Service. However you might be better off using one of the Out of Box SharePoint Web Services.


I´m not sure what you´re after here, I mean

  1. Testing your SPDataSource in console app (nothing to do like said by JD)
  2. Getting data from sharepoint in a datasource manner.

If your´re going for solution 2 you could use a linqdatasource instead of the spdatasource. See my post on this if that´s what your´re looking for.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »