2

I am trying to add a SiteFeedWebPart to a SharePoint page by using CSOM. I exported the XML from a Site and then try to import into the page using the ImportWebPart . The XML file is as follows

var webPartSchemaXml = "<?xml version='1.0' encoding='utf-8'?>" +
                       "<WebPart xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns='http://schemas.microsoft.com/WebPart/v2'>" +
                       "<Title>Site Feed</Title>" +
                        "<FrameType>None</FrameType>" +
                       "<Description>Site Feed contains microblogging conversations on a group site.</Description>" +
                      "<IsIncluded>true</IsIncluded>" +
                      "<ZoneID>right</ZoneID>" +
                      "<PartOrder>0</PartOrder>" +
                      "<FrameState>Normal</FrameState>" +
                      "<Height />" +
                      "<Width />" +
                      "<AllowRemove>true</AllowRemove>" +
                     "<AllowZoneChange>true</AllowZoneChange>" +                                        "<AllowMinimize>true</AllowMinimize>" +                                          "<AllowConnect>true</AllowConnect>" +                          "<AllowEdit>true</AllowEdit>" +                           "<AllowHide>true</AllowHide>" +
                        "<IsVisible>true</IsVisible>" +
                      "<DetailLink />" +
                      "<HelpLink />" +
                        "<HelpMode>Modeless</HelpMode>" +
                       "<Dir>Default</Dir>" +
                        "<PartImageSmall />" +
                         "<MissingAssembly>Cannot import this Web Part.</MissingAssembly>" +
                       "<PartImageLarge>/_layouts/15/images/wp_pers.gif</PartImageLarge>" +
                    "<IsIncludedFilter />" +"<Assembly>Microsoft.SharePoint.Portal, Version='16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'</Assembly>" +
"<TypeName>Microsoft.SharePoint.Portal.WebControls.SiteFeedWebPart</TypeName>" +
                                    "</WebPart>";

I get a Value not found error

 var pageUrl = "Site/Pages/Home.aspx";
var zoneid = HomePageBO.LeftZone;
           var zoneIndex = 1;

           using (ClientContext context = GetContext())
           {
               var page = context.Web.GetFileByServerRelativeUrl(pageUrl);
               var wpm = page.GetLimitedWebPartManager(PersonalizationScope.Shared);
               var importedWebPart = wpm.ImportWebPart(webPartSchemaXml);

               var webPart = wpm.AddWebPart(importedWebPart.WebPart, zoneid, zoneIndex);
               context.Load(webPart);
               context.ExecuteQuery();
           }

The error is not descriptive and does not provide information whether the XML is wrong or if there is a problem with the page or when the webpart is added.

  • Can you please post exact error message, line and stacktrace of the exception? – Sergei Sergeev Nov 16 '16 at 21:24
  • I've run into something similar before when my zoneid was not right. Hope that helps! – Glenn Ferrie Nov 17 '16 at 1:27
  • It still comes up with the same error – user1339913 Nov 17 '16 at 12:12
0

The error message Value not found error is not very descriptive. It can be caused by the following reasons

  • Incorrect PageUrl Path
  • Zone index
  • Incorrect XML

To get the correct XML check if the Webpart is part of on the OOB sharepoint installed. Go to the Webpart Gallery and download the webpart and extract the XML.

 var pageUrl = "/site/Pages/Home.aspx";
           var webPartSchemaXml = "<?xml version='1.0' encoding='utf-8'?>" +
                                     "<WebPart xmlns='http://schemas.microsoft.com/WebPart/v2'>" +
                                         "<Assembly>Microsoft.SharePoint.Portal, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>" +
                                         "<TypeName>Microsoft.SharePoint.Portal.WebControls.SiteFeedWebPart</TypeName>" +
                                         "<Title>$Resources:spscore,SiteFeed_WebPart_Title;</Title>" +
                                         "<Description>$Resources:spscore,SiteFeed_WebPart_Description;</Description>" +
                                         "<FrameType>None</FrameType>" +
                                         "<PartImageLarge>/_layouts/15/images/wp_pers.gif</PartImageLarge>" +
                                     "</WebPart>";
           var zoneid = LeftZone;
           var zoneIndex = 1;
             using (ClientContext context = SiteDAL.GetContext())
             {
                 var page = context.Web.GetFileByServerRelativeUrl(pageUrl);
                 var wpm = page.GetLimitedWebPartManager(PersonalizationScope.Shared);
                 var importedWebPart = wpm.ImportWebPart(webPartSchemaXml);

                 var webPart = wpm.AddWebPart(importedWebPart.WebPart, zoneid, zoneIndex);
                 context.Load(webPart);
                 context.ExecuteQuery();

             }

Another approach to add a webpart is using the upload method shown in the BestPractices

Hope it helps

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.