Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here is how I did it. It worked really well. I had a feature that created several list instances and provisioned the What's New web part. In the Feature Receiver, I looped through all of the list instances, indexed the Modified field, and then added the list to the web part:</p> <pre><code>private void ConfigureLists(SPWeb web, SPFeatureReceiverProperties properties) { List&lt;Guid&gt; ids = new List&lt;Guid&gt;(); SPElementDefinitionCollection elements = properties.Feature.Definition.GetElementDefinitions(new CultureInfo((int)web.Language, false)); foreach (SPElementDefinition element in elements) { if ("ListInstance" == element.ElementType) { XmlNode node = element.XmlDefinition; SPList list = web.Lists[node.Attributes["Title"].Value]; SPField field = list.Fields[SPBuiltInFieldId.Modified]; if (!field.Indexed) { field.Indexed = true; field.Update(); } ids.Add(list.ID); } } string targetConfig = string.Empty; foreach (Guid id in ids) { targetConfig += string.Format("'{0}',''\n", id); } SPFile file = web.GetFile("Pages/default.aspx"); file.CheckOut(); using (SPLimitedWebPartManager manager = file.GetLimitedWebPartManager(PersonalizationScope.Shared)) { WhatsNewWebPart webpart = null; foreach (System.Web.UI.WebControls.WebParts.WebPart eachWebPart in manager.WebParts) { webpart = eachWebPart as WhatsNewWebPart; if (null != webpart) { break; } } if (null != webpart) { webpart.TargetConfig = targetConfig; manager.SaveChanges(webpart); } } file.CheckIn("ConfigureWebParts"); file.Publish("ConfigureWebParts"); file.Approve("ConfigureWebParts"); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload