답변됨 Display document library from parent site

  • 8. srpna 2012 11:57
     
      Obsahuje kód

    Hi,

    i have to programmatically create a page in different sites including a webpart linked to  the document Library "Images" of their parent site.

    The problem is that this following code doesn't work :

    XsltListViewWebPart ImagesListWebPart = new XsltListViewWebPart();
    ImagesListWebPart.ListName = curWeb.ParentWeb.Lists["Images"].ID.ToString("B").ToUpper();
    ImagesListWebPart.ViewGuid = curWeb.ParentWeb.Lists["Images"].DefaultView.ID.ToString("B").ToUpper();
    ImagesListWebPart.ChromeType = System.Web.UI.WebControls.WebParts.PartChromeType.None;
     manager.AddWebPart(ImagesListWebPart, "NorthId", 3);

    Of course, i get a "List not found" Exception, because i can't refer to a list (or document library) which is contained in the parent site.

    Do you have any solutions ?

    Thank you


Všechny reakce

  • 8. srpna 2012 13:44
     
     

    Hello,

    You cant add the list view webpart from the parent site programatically,

    this also cant possible with the UI also.

    you can add the list view webpart from the current site only,



    Hiren Patel | Please click "Propose As Answer" if this post solves your problem or "Vote As Helpful" if this post has been useful to you.

  • 13. srpna 2012 9:15
    Moderátor
     
     Odpovědět

    Hi,

    If you want to display list from parent's site, you can refer to this:http://www.youtube.com/watch?v=0SfpgoEUlIw 

    You should first export the web part to the web part gallery in the top-lever site of current site collection, and then you can use the web part to the subsites under this web site collection.

    If you want to complete it programmatically, you can get further help in http://social.technet.microsoft.com/Forums/en/sharepoint2010programming/threads


    Xue-mei Chang

    TechNet Community Support