能否批量将指定内容类型的所有内容项添加至2sxc列表?
Bulk-Add All Items from a Specific Content Type to a 2sxc List (No Manual Clicking!)
Great question—manually adding dozens or hundreds of content items to a 2sxc List is a total time-suck, so let’s break down the most efficient ways to handle this in bulk:
1. Use the 2sxc Admin UI (Quick & No-Code)
If you’re working within the same DNN/2sxc instance, the built-in bulk selection tool is your first go-to:
- Open your 2sxc List module’s management interface, then navigate to the Items tab
- Look for the
Add Existingbutton (usually in the top toolbar) - In the content picker modal, use the dropdown filter to select your target content type
- Batch-select items: Use
Ctrl+Click(Windows) orCmd+Click(Mac) to pick multiple items, or check the top checkbox to select all items in the filtered list - Hit
Add Selected—done! No more tedious one-by-one clicks.
2. Use a Razor Script (For Large Datasets or Automation)
If you have hundreds/thousands of items (and the UI starts lagging), a quick Razor script will handle this in seconds. Here’s a template you can adapt:
// Replace with your source content type name var sourceContentType = "YourSourceContentType"; // Replace with your List's content type name var listContentType = "YourListContentType"; // Replace with the field name in your List that references the source items var referenceFieldName = "RelatedSourceItem"; // Get all source items var sourceItems = App.Data[sourceContentType].ToList(); // Loop through and add each to the List (as a reference, not a copy) foreach (var item in sourceItems) { // Create a new List item linked to the source content App.Data.Create(listContentType, new { // Map required fields - adjust these to match your List's fields Title = item.Title, [referenceFieldName] = item.EntityId }); } // Optional: Confirm completion <p>Successfully added @sourceItems.Count items to the List!</p>
How to use this:
- Create a new 2sxc App or use an existing one, then add a new Razor view
- Paste the code, replace the placeholder values with your actual content type/field names
- View the page once to run the script (it will execute immediately)
- Important: Delete or disable the view after running to avoid accidentally duplicating items
Critical Notes Before You Start
- Backup your data first: Bulk operations can go wrong—take a DNN content backup before proceeding
- If your List uses copies of content (not references), adjust the script to copy field values instead of linking EntityIds
- For extremely large datasets (10k+ items), add a batch loop with small delays to avoid timeouts
内容的提问来源于stack exchange,提问作者Joe Craig
相关产品推荐
相关产品推荐

