Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Add Webpart to a WebpartPage grammatically using SANDBOX solution

$
0
0
Hi
I can create webpart-pages using the following code.
protected void btnSubmit_Click(object sender, EventArgs e)
        {
            using (SPWeb oWebsite = SPContext.Current.Web)
            {
                SPList olist = oWebsite.Lists["Site Pages"];
                string xml = GetCreateWebPartPage(olist.ID.ToString(), "SamplePage", 4);
                oWebsite.ProcessBatchData(xml);


            }
        }
private string GetCreateWebPartPage(String list, string pageTitle, int layoutTemplate)
        {
            const string newItemTemplate = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +"<Batch>" +"<Method ID=\"0,NewWebPage\">" +"<SetList Scope=\"Request\">{0}</SetList>" +"<SetVar Name=\"Cmd\">NewWebPage</SetVar>" +"<SetVar Name=\"ID\">New</SetVar>" +"<SetVar Name=\"Type\">WebPartPage</SetVar>" +"<SetVar Name=\"WebPartPageTemplate\">{2}</SetVar>" +"<SetVar Name=\"Overwrite\">true</SetVar>" +"<SetVar Name=\"Title\">{1}</SetVar>" +"</Method>" +"</Batch>";
            var newItemXml = string.Format(newItemTemplate, list, pageTitle, layoutTemplate);

            return newItemXml;
        }
Can anyone tell me using C#,how can I add a webPart (eg.MyCustomWebpart) to the page created from above code ?

(I heard we can use declarative approach to provisioning webpart. But I unable to find the solution how can use declarative approach + C#)
http://blog.mastykarz.nl/inconvenient-provisioning-web-parts-wiki-pages-sandboxed-solutions/



S H A J A N


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>