0

I want to add the search box web part and search result web part programmatically using OM in Visual Studio. I searched over internet and found this which indicates to manually create web part and export it. Then copy the <webpart> tag to string variable and add it to site.

Is there another way to add these webparts using objects? I even don't know from where to start? as I am very beginner to SharePoint.

If there any then please provide any reference or suggestions.

3
  • Is there a specific reason you need to do tis through the OM? – Matthew McDermott Oct 19 '13 at 0:52
  • @MatthewMcDermott asks a great question. He is a master of using search web parts in SharePoint. In case it helps, I gave an answer to your stated question anyway. :) – Tom Resing Oct 20 '13 at 19:32
  • 1
    Thanks @TomResing! I guess my point is that there should be no difference in the Search Web Parts from any other web parts. The method should be exactly the same. That said, there may be feature dependencies. – Matthew McDermott Oct 23 '13 at 15:27
1

To add a web part through the object model, you can use getLimitedWebPartManager and call the addwebpart method.

See the answers at How to programmatically add a webpart to a page? for more detail.

Also, look at Programmatically Moving, Adding, and Removing Web Parts in SharePoint 2010 for examples

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.