I'm using ListViewWebPart to display contents of SPFolder (subfolder inside a list) to display its contents.
Below is the code to implement this:
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);
}
The contents display correctly but the toolbar is the parent list's toolbar and not the folder's toolbar.
How can i modify the toolbar context to load the context of the spfolder?