2

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?

5
+50

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);
    }
}

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.