Question

I have to display a list (located in a subsite) in the welcome page of the parent site. (Inside a WebPart most likely)

I don't have acess to sharepoint designer and i have SharePoint 2013.

Besides, i need to customise this list (using JSLink or tuning the default view etc..) so Content query webPart is not a solution for me (if i am not wrong)

I tried this code but List does not exist error displays when i try to add the webPart i created from visual studio

var xlv = new XsltListViewWebPart();
    using (var oSite = new SPSite(" http : / / app:3333/ "))
    {
        using (var oWeb = oSite.OpenWeb("/ProxymIT/Direction"))
        {
            var oList = oWeb.Lists["AdministrativeNotes"];  //your list name
            xlv.ListId = oList.ID;
            xlv.ViewGuid = oList.DefaultView.ID.ToString(); //default view
            Controls.Add(xlv);
        }
    }

Am i missing something?

Était-ce utile?

La solution

You're missing the WebId property:

var xlv = new XsltListViewWebPart();
using (var oSite = new SPSite(" http : / / app:3333/ "))
{
    using (var oWeb = oSite.OpenWeb("/ProxymIT/Direction"))
    {
        var oList = oWeb.Lists["AdministrativeNotes"];  //your list name
        xlv.WebId = oWeb.ID;
        xlv.ListId = oList.ID;
        xlv.ViewGuid = oList.DefaultView.ID.ToString(); //default view
        Controls.Add(xlv);
    }
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange
scroll top