SharePoint: Programatically add XSLTList view webpart to page

Following example shows how to add XSLT list view webpart to a webpart page:
Please note: The code to set the toolbar will work in MOSS 2007 and SP 2010 only. It doesn't work in SP 2013.
//Display items with latest modified date
string query = "<OrderBy><FieldRef Name=\"Modified\" Ascending='FALSE'/></OrderBy>";

//Total number of rows to be shown in Lists on homepage
uint rowCount = 20;

//Get Reference of Task List
SPList taskList = oWeb.Lists["Tasks"];
StringCollection relevantColumns = CreateViewColumns();
SPView taskView = taskList.Views.Add("Recent Tasks", relevantColumns, query, rowCount, false, false);
string zoneID = "Zone ID";
int zoneIndex = 1;
AddListsToHomePage(taskList, taskList.Title, zoneID, zoneIndex, taskView);

private StringCollection CreateViewColumns()
    StringCollection viewFieldsCollection = new StringCollection();
    string tasksColumns = "ID;Title";
    string[] columns = tasksColumns.Split(';');
    foreach (string column in columns)
    return viewFieldsCollection;

private void AddListsToHomePage(SPList listToAdd, string title, string zoneID, int zoneIndex, SPView view)
    XsltListViewWebPart lvwp = new XsltListViewWebPart();
    lvwp.ListName = listToAdd.ID.ToString("B").ToUpper();
    lvwp.ViewGuid = view.ID.ToString("B").ToUpper();
    lvwp.Title = title;
    using (SPLimitedWebPartManager webpartManager = web.GetLimitedWebPartManager(web.Url + "default.aspx", System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared))
        webpartManager.AddWebPart(lvwp, zoneID, zoneIndex);

    //Set toolbar type to Freeform
    MethodInfo ensureViewMethod = lvwp.GetType().GetMethod("EnsureView", BindingFlags.Instance | BindingFlags.NonPublic);
    object[] ensureViewParams = { };
    ensureViewMethod.Invoke(lvwp, ensureViewParams);
    FieldInfo viewFieldInfo = lvwp.GetType().GetField("view", BindingFlags.NonPublic | BindingFlags.Instance);
    SPView spView = viewFieldInfo.GetValue(lvwp) as SPView;
    Type[] toolbarMethodParamTypes = { Type.GetType("System.String") };
    MethodInfo setToolbarTypeMethod = spView.GetType().GetMethod("SetToolbarType", BindingFlags.Instance | BindingFlags.NonPublic, null, toolbarMethodParamTypes, null);
    object[] setToolbarParam = { "Freeform" };
    setToolbarTypeMethod.Invoke(spView, setToolbarParam);

    //Set tabular view to false, so that bulk editing is not allowed
    spView.TabularView = false;
    //Update the default view
    SPView defaultView = listToAdd.DefaultView;

    //Total number of rows to be shown in Deafault view of Lists
    uint rowCount = 100;
    defaultView.RowLimit = rowCount;
    defaultView.Paged = true;