4

I am looking for a way to actually create a result source with C# CSOM. I only find examples where I specify an existing result source like this answer. I am developing a SharePoint provider hosted addin and I must create and configure a couple of search web parts with my CSOM code in a remote MVC application with an AppInstalled Event Receiver. I can't use any server code nor provision it. That is why I must do it with C# CSOM.

So does anyone know of a way to do this?

3
+50

It is possible to create a result source with CSOM. Basically what you do is:

  1. Manually create the result source in SharePoint (in the site, sitecollection or tenant level depending on your requirements)
  2. Export the search configuration, which gives you an XML file.

  3. Use CSOM to import the search configuration to another site, sitecollection or tenant.

Have a look at this PnP video and sample:

https://channel9.msdn.com/blogs/OfficeDevPnP/How-to-Export-and-Import-Search-Configurations-with-CSOM

https://github.com/SharePoint/PnP/tree/master/Samples/Core.SearchSettingsPortability

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.