Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a repository of files... I'd like to create a ListView Webpart wich receives the path in the tree and show the files in the document library... It's possible to do this by code? Is there any tutorial? The only way is to derivate a new class from ListViewWebPart wich receives parameters or it is possible to do this in a easy way?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

It's not possible to extend a ListView Webpart, so i create a base webpart and inserted in this "container" a ListView WebPart..

This get parameters directly from the url / parameters and select the list this way!

Take a look =)

public partial class VisualWebPart1UserControl : UserControl
{
    private Microsoft.SharePoint.WebPartPages.ListViewWebPart myListView;
    protected override void CreateChildControls()
    {
        base.CreateChildControls();
        SPSite oSiteCollection = SPContext.Current.Site;
        string listName = Context.Request.Param["List"];
        SPWeb oWebSite = SPContext.Current.Web;
        myListView = new Microsoft.SharePoint.WebPartPages.ListViewWebPart();
        myListView.Visible = true;
        myListView.EnableViewState = true;
        SPList list = oWebSite.Lists[listName];

        myListView.ListName = list.ID.ToString("B").ToUpperInvariant();
        myListView.TitleUrl = list.DefaultViewUrl;
        myListView.WebId = list.ParentWeb.ID;

        myListView.ListId = (System.Guid)list.ID;
        myListView.ViewGuid = list.DefaultView.ID.ToString("B").ToUpperInvariant();

        myListView.HelpMode = WebPartHelpMode.Modeless;

        Controls.Add(myListView);
    }

Hope this will help someone =)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.