I want to add a webpart to a page in SharePoint online programmatically. I know the page name, but don't the webpartzone id since it is SharePoint online. Is it still possible to add my webpart to the page programmatically? If yes how?
2 Answers
One of the challenges when working with Sandboxed Solutions is how to provision Web Parts instances to pages. If you have done this before in a Farm Solution you know, that in order to add a Web Part to a page programmatically in SharePoint you have to retrieve the instance of the SPLimitedWebPartManager class and use it to add the instance of a Web Part to a page. Unfortunately, as the SDK mentions, the SPLimitedWebPartManager class is not available in Sandboxed Solutions which means that you cannot programmatically add a Web Part to a page from within a Sandboxed Solution.
For more detials check:
http://blog.mastykarz.nl/inconvenient-provisioning-web-parts-wiki-pages-sandboxed-solutions/
-
4Besides that, sandboxed solutions containing code are not supported in Office 365 Sep 18, 2014 at 5:40
What I would do is take a look at the OfficeDev Patterns and Practices project on Github. There are plenty of examples for writing CSOM for SharePoint Online.
All examples are using the new App Model with plenty of helper classes available to do what you need.
The projects in particular that you will want are the Provisioning.Pages
and Provisioning.Publishing
ones.
Hope these help!