Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a Custom Webpart deployed in the Site, to which I need to retrieve the XML definition programmatically using Client side object model, can anybody help?

EDIT: I used the following code.

    string strSiteUrl = SiteUrl_txt.Text;
        using (ClientContext cContext = new ClientContext(strSiteUrl))
        {
            //open Web
            Web oWeb = cContext.Web;
            cContext.Load(oWeb);
            File page = oWeb.GetFileByServerRelativeUrl("MySiteUrl");
            LimitedWebPartManager limitedWebPartManager = page.GetLimitedWebPartManager(PersonalizationScope.Shared);
            cContext.Load(limitedWebPartManager, wps => wps.WebParts.Include(wp => wp.WebPart.Properties, wp => wp.WebPart.Title, wp => wp.WebPart.TitleUrl));
            cContext.ExecuteQuery();

            foreach (WebPartDefinition wp in limitedWebPartManager.WebParts)
            {

                if (wp.WebPart.Properties.FieldValues.ContainsKey("UniqueValue"))
                {
                    //  Here I need to extract the XML definition, but not sure what should I 
                    //  add here so that I could get the entire XML definition, like the one 
                    //  we get when we export the webpart as XML in webpart gallery mannually.
                }
            }
share|improve this question
1  
What have you tried? –  Codingo Jul 27 at 9:58
    
I have updated the question with code I have tried. –  Shashikant K Jul 27 at 11:27
    
This is similar to what you want: stackoverflow.com/questions/11814829/… –  Akhoy Jul 27 at 12:14
    
@uberz91, Thanks. I did tried the same. I am getting SOAP exceptions. also there is no way we can export the XML programmatically using client side code? –  Shashikant K Aug 4 at 13:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.