ListViewWebPart

时间:2012-01-17 09:25:21

标签: sharepoint

我正在使用listviewwebpart来显示SPFolder(列表中的子文件夹)的内容以显示其内容。 Beolw是实现相同的代码:

  protected override void CreateChildControls()
  {
    try
    {
      base.CreateChildControls();

      webPart = new ListViewWebPart();

      using (var site = new SPSite(SPContext.Current.Web.Url))
      using (var web = site.OpenWeb())
      {
        clientName = DataLogic.Client.GetClientName(Constants.Session.Client_ClientID);
        var library = web.Lists["Account"];
        webPart.ListName = library.ID.ToString("B").ToUpper();
        webPart.ListId = library.ID;   
        SPFolder folder = web.GetFolder("/Account/" + clientName);
        if (folder.Item != null)
        {
          SPContentTypeId folderctid = folder.Item.ContentType.Id;

          //set the folder url
          SetPrivateFieldValue(webPart, "rootFolder", folder.Url);
          SetPrivateFieldValue(webPart, "folderCtId", folderctid.ToString());
          webPart.ListViewXml = library.DefaultView.GetViewXml();            
          webPart.ChromeType = PartChromeType.None;
          this.mainSec.Controls.Add(webPart);
        }
        else
        {
          lblWarning.Text = "There is no document library associated with client " + clientName;
        }           

      }

    }
    catch (Exception ex)
    {

    }
  }

  private static void SetPrivateFieldValue(object obj, string fieldName, string val)
  {
    FieldInfo fi = obj.GetType().GetField(fieldName, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
    fi.SetValue(obj, val);
  }

内容显示正确,但工具栏是父列表的工具栏,而不是文件夹的工具栏。 如何修改工具栏上下文以加载spfolder的上下文?

0 个答案:

没有答案