I've recently found this nice thread on adding an existing webpart using the csom: Add an existing WebPart Using the Sharepoint client object Model

I've tried the same approach for an app part (so an app part packaged in a .app) however I haven't found this particular part to reside in the web part gallery and as such I can't edit and retrieve this app part's XML. (I'm sure it is correctly installed as I can add the part while editing the page after I've added the app to the page. I've also compared the count of the items in the webpart gallery before and after installing the app and it seems to stay the same so I don't think I'm overlooking the part.)

What location or in what manner would I be able to retrieve this xml? Or should I try a different approach to adding an app part programmatically?

EDIT: I found a way to export as .webpart.

  • Add the web part to the site
  • Open the site page .aspx using sharepoint designer.
  • Add the following attribute to the ClientWebPart: ExportMode="All"
  • save your changes
  • Now you can go back, edit your page in sharepoint and then choose "Export"

Glad you found the answer, there are a bunch of ways to export the webpart. I have created a javascript snippet to allow for exporting of all webparts just by running it in your browser developer console which I tested on 2013 and SP Online. You can also download a bookmarklet of it at the link provided.

(function() {
    var script = document.createElement("SCRIPT");
    script.src = 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js';
    script.type = 'text/javascript';

    var checkReady = function(callback) {
        if (window.jQuery) {
        else {
            window.setTimeout(function() { checkReady(callback); }, 100);

    checkReady(function($) {
            var wpGuid = $(this).attr('webpartid');
            var pageUrl = location.origin + _spPageContextInfo.serverRequestPath;
            var requestUrl = _spPageContextInfo.siteAbsoluteUrl + "/_vti_bin/exportwp.aspx?pageurl=" + pageUrl + "&guidstring=" + wpGuid;
            $(this).prepend("<a href='" + requestUrl + "'>Export Me</a>"); 

By running the above this will generate an export link on every visible webpart on the page.

Source: http://www.migee.com/2015/11/19/export-any-sharepoint-webpart-in-a-click-with-this-bookmarklet-or-javascript/

  • Works! When I clicked the Export Me link in Internet Explorer, SharePoint gave me an error: "Something went wrong" but in Google Chrome it worked without a hitch. Thanks! Jul 26 '17 at 15:48

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.