I add an XsltListViewWebpart to a page in an event receiver like this:
public void CreateWebPart(SPList documentsList, SPLimitedWebPartManager wpm)
{
var documentsWP = new XsltListViewWebPart();
documentsWP.ListId = documentsList.ID
wpm.AddWebPart(documentsWP, "Left", 0);
}
This works fine, but I want to change it around a bit. I want to edit the columns that are displayed, and I want to remove the little toolbar at the bottom that allows you to add items. My first attempt was this:
public void CreateWebPart(SPList documentsList, SPLimitedWebPartManager wpm)
{
var documentsWP = new XsltListViewWebPart();
documentsWP.ListId = documentsList.ID;
documentsWP.Toolbar = "None"; //this does nothing?
wpm.AddWebPart(documentsWP, "Left", 0);
}
But that did nothing. After that I tried the following:
public void CreateWebPart(SPList documentsList, SPLimitedWebPartManager wpm)
{
var documentsWP= new XsltListViewWebPart();
documentsWP.ListId = documentsList.ID;
StringBuilder xml = new StringBuilder();
xml.Append("<View MobileView='TRUE' Type='HTML'>");
xml.Append("<Query></Query>");
xml.Append("<ViewFields><FieldRef Name='DocIcon'/><FieldRef Name='LinkFilename'/></ViewFields>");
xml.Append("<RowLimit Paged='TRUE'>30</RowLimit>");
xml.Append("<Aggregations Value='Off'/>");
xml.Append("<Toolbar Type='None'/></View>");
documentsWP.XmlDefinition = xml.ToString();
documentsWP.AllowEdit = false;
wpm.AddWebPart(documentsWP, "Left", 0);
}
But still the toolbar is shown, and still other fields are shown (the Modifier field). How can I programmatically set the displayed columns? How can I hide the toolbar?