Quantcast
Channel: SharePoint 2013 - General Discussions and Questions forum
Viewing all articles
Browse latest Browse all 26374

adding listviewwebpart to home page by code in sharepoint 2013

$
0
0

Hi,

I have this code done for sharepoint 2010 which creates a list and adds it to the home page for site. But this does not working with sharepoint 2013. this list is being treated as app. How can i add the app to the home by code.

   // Add The List as a Links List
                Guid listguid = web.Lists.Add(title, descr, template);

                // Get The List Reference
                SPList linksList = web.Lists[listguid];

                linksList.EnableVersioning = true;
                linksList.Update();

                // Create The Web Part
                using (ListViewWebPart listViewWebPart = new ListViewWebPart())
                {
                    listViewWebPart.ZoneID = "Left";
                    listViewWebPart.ListName = linksList.ID.ToString("B").ToUpperInvariant();
                    listViewWebPart.ViewGuid = linksList.DefaultView.ID.ToString("B").ToUpperInvariant();

                    // Get The Reference To The Default Page For Adding the List To The Entry Screen
                    SPLimitedWebPartManager splimitedWebPartManager = web.GetLimitedWebPartManager(
                        DefaultPage, System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
                    splimitedWebPartManager.AddWebPart(listViewWebPart, "Left", splimitedWebPartManager.WebParts.Count);

                    web.Update();

                    splimitedWebPartManager.Dispose();
                }

                result = linksList;

Thanks


Viewing all articles
Browse latest Browse all 26374

Trending Articles



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