SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When defining a listview webpart in a custom site definition, how can I make sure that the view has the columns that I want it to show?

The standard view shows these column: Title, Assigned To and Modified. What I want it to show is these columns: Title, Due Date.

What's the best way of doing so?

share|improve this question
up vote 1 down vote accepted

The easiest way is to build the View you want into your list definition. Then in your ListViewWebPart refer it to that view.

In CAML, this will be something like:

<View List="Lists/Tasks" BaseViewID="7" WebPartZoneID="Left" WebPartOrder="5" />

BaseViewID is the identifier for the View in your List Definition.

However, you might want to do this programmatically - for example, if you create the view within your list programmatically too. In that case, you'll need something like:

SPView myView = ...
using (SPLimitedWebPartManager manager = web.GetLimitedWebPartManager("default.aspx", PersonalizationScope.Shared))
    using (ListViewWebPart webPart = new ListViewWebPart())
        webPart.Title = "My List";
        webPart.ListName = web.Lists["MyList"].ID.ToString("B").ToUpper();
        webPart.ViewGuid = myView.ID.ToString("B").ToUpper();
        manager.AddWebPart(webPart, "Left", 3);
share|improve this answer

Your Answer


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.