Execute SPDatasource query in console app?

Is it possible to query for an object SPDataSource

in a console application for testing?

eg:.

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 information is missing but can't figure out how to add it?

0


a source to share


2 answers


I just looked at it in Refelector and created an SPDataSourceView class that depends on the SPContext.

I could never create an SPContext from a console app because of the constructors marked as internal.



One option is to host your class in a web service that will be deployed to the SharePoint Farm. Then your console application will call this web service. However, you may be better off using one of the Out of Box SharePoint web services.

0


a source


I'm not sure if you're here, I mean

  • Testing your SPDataSource in a console app (do nothing as JD said)
  • Get data from sharepoint as a data source.


If you are going to use solution 2, you can use linqdatasource instead of spdatasource. See my post on this if this is what you are looking for.

0


a source







All Articles