Imported from aspose-slides/agentic-net-examples (
AGENTS.md). Install upstream withnpx skills add aspose-slides/agentic-net-examples. Copyright stays with the author.
Aspose.Slides for .NET Examples
AI-friendly repository containing validated C# examples for Aspose.Slides.
Persona
You are a C# developer specializing in presentation processing using Aspose.Slides for .NET. When working in this repository:
- Each
.csfile is a standalone Console Application - Do not create multi-file projects
- All examples must compile with
dotnet build - All examples must run with
dotnet run - Follow the repository conventions and boundaries strictly
- Use the Command Reference section for build and run commands
Repository Overview
This repository contains 2245 working code examples demonstrating Aspose.Slides for .NET capabilities.
Statistics (as of 2026-09-17):
- Version: 26.9.0
- Total Examples: 2245
- Categories: 19
Category Details
3d-presentations
- Examples: 33
- Guide: AGENTS.md
animations
- Examples: 31
- Guide: AGENTS.md
comments-and-notes
- Examples: 117
- Guide: AGENTS.md
conversion
- Examples: 378
- Guide: AGENTS.md
design-presentations
- Examples: 157
- Guide: AGENTS.md
manage-presentation
- Examples: 64
- Guide: AGENTS.md
manage-presentation-content
- Examples: 101
- Guide: AGENTS.md
manage-presentation-media-files
- Examples: 149
- Guide: AGENTS.md
manage-presentation-text
- Examples: 104
- Guide: AGENTS.md
manage-tags-and-custom-data
- Examples: 40
- Guide: AGENTS.md
math-equations
- Examples: 27
- Guide: AGENTS.md
presentation-ink-objects
- Examples: 35
- Guide: AGENTS.md
secure-presentations
- Examples: 29
- Guide: AGENTS.md
vba-macros
- Examples: 34
- Guide: AGENTS.md
working-with-charts
- Examples: 463
- Guide: AGENTS.md
working-with-shapes
- Examples: 208
- Guide: AGENTS.md
working-with-slides
- Examples: 123
- Guide: AGENTS.md
working-with-smartart
- Examples: 121
- Guide: AGENTS.md
working-with-tables
- Examples: 31
- Guide: AGENTS.md
Boundaries
✅ Always
These rules are mandatory for every example.
Use explicit types where clarity matters
Aspose.Slides.Presentation presentation = new Aspose.Slides.Presentation("input.pptx");
Aspose.Slides.ISlide slide = presentation.Slides[0];
Use fully qualified namespaces where ambiguity exists
Aspose.Slides.Export.SaveFormat format = Aspose.Slides.Export.SaveFormat.Pptx;
Use using blocks for disposable objects
using (Aspose.Slides.Presentation presentation = new Aspose.Slides.Presentation("input.pptx"))
{
presentation.Save("output.pptx", Aspose.Slides.Export.SaveFormat.Pptx);
}
Save the presentation after modifications
presentation.Save("output.pptx", Aspose.Slides.Export.SaveFormat.Pptx);
⚠️ Ask First
Check with a human before doing any of these:
- Creating multi-file projects
- Adding NuGet packages other than Aspose.Slides
- Using deprecated APIs
- Modifying repository infrastructure
🚫 Never
- Never use
Aspose.Slides.SaveFormat - Never mix chart APIs from incorrect namespaces
- Never rely on
System.Drawing.Imagewhen Slides APIs exist - Never modify generated
agents.mdfiles - Never modify generated
.csprojtemplates
Common Mistakes (Anti-Patterns)
Domain Knowledge
-
Replace fonts explicitly before saving the presentation.
UseIFontData,FontData, andFontsManager.ReplaceFont(...)to swap one font family with another across the deck, then save the updated file.
Example: CreateIFontData sourceFont = new FontData("Arial");,IFontData destFont = new FontData("Times New Roman");, callpresentation.FontsManager.ReplaceFont(sourceFont, destFont);, and save asoutput.pptx. -
Clone a slide into a specific section to preserve presentation structure.
When duplicating slides, create or append the destination section first and useSlides.AddClone(...)with the targetISection.
Example: Add a rectangle topresentation.Slides[0], createISection section2 = presentation.Sections.AppendEmptySection("Section 2");, then callpresentation.Slides.AddClone(presentation.Slides[0], section2);. -
Replace placeholder text by iterating shapes and updating only auto shapes.
Loop throughslide.Shapes, checkshape.Placeholder != null, cast the shape toIAutoShape, and updateTextFrame.Text.
Example: Iterate the first slide’s shapes and set((IAutoShape)shape).TextFrame.Text = "Updated title";only for placeholder shapes before saving. -
Animate chart categories element-by-element through the slide timeline.
Access the chart from the slide’s shape collection, add a base effect toTimeline.MainSequence, then loop through categories and series to addByElementInCategoryeffects.
Example: Castslide.Shapes[0]toAspose.Slides.Charts.IChart, add aFadeeffect, then use nested loops overchart.ChartData.Categories.Countandchart.ChartData.Series.Countto addAppearanimations. -
Export a shape as a PNG thumbnail without exporting the whole slide.
Create a shape, style it, callshape.GetImage(...), and save the returnedIImagewithAspose.Slides.ImageFormat.Png.
Example: Add a rectangle, setFillFormat.FillType = NoFill, setLineFormat.SketchFormat.SketchType = Scribble, then callshape.GetImage(Aspose.Slides.ShapeThumbnailBounds.Shape, 2f, 2f)and save it asshape.png. -
Access SmartArt by walking the slide’s shape collection and casting matching shapes.
To inspect or process SmartArt content, iterateslide.Shapes, detect SmartArt shapes, and cast them toAspose.Slides.SmartArt.ISmartArtorSmartArt.
Example: Loop throughslide.Shapes, checkif (shape is Aspose.Slides.SmartArt.ISmartArt), cast it, then inspectsmartArt.AllNodesto read node text and hierarchy. -
Read SmartArt child nodes when you need hierarchy, level, and position data.
For tree-style processing, iterateAllNodes, then iterate each node’sChildNodesto access nested content and metadata likeLevelandPosition.
Example: Cast a SmartArt shape toSmartArt, loop oversmart.AllNodes, then for each parent node loop overparentNode.ChildNodesand readchildNode.TextFrame.Text. -
Embed audio in a slide and configure playback behavior directly on the audio frame.
After creating an embedded audio frame, set playback options such asPlayAcrossSlides,RewindAudio,Volume, andPlayMode.
Example: Callslide.Shapes.AddAudioFrameEmbedded(...), then setaudioFrame.PlayAcrossSlides = true;,audioFrame.RewindAudio = true;, andaudioFrame.PlayMode = Aspose.Slides.AudioPlayModePreset.Auto;. -
Add hyperlinks through text portions inside an auto shape rather than on the shape itself.
Create an auto shape, add text, then attach the hyperlink to the first text portion usingPortionFormat.HyperlinkClick.
Example: Create a rectangle, callshape.AddTextFrame("Open site");, then setshape.TextFrame.Paragraphs[0].Portions[0].PortionFormat.HyperlinkClick = new Aspose.Slides.Hyperlink("https://example.com");. -
Store images inside table cells by using picture fill formatting on the target cell.
Add a table, load an image, insert it into the presentation image collection, and assign it throughCellFormat.FillFormat.PictureFillFormat.Picture.Image.
Example: Create a table withslide.Shapes.AddTable(...), load an image withAspose.Slides.Images.FromFile("input.jpg"), add it viapresentation.Images.AddImage(...), then set the first cell’s fill type toPictureand apply the image.
Command Reference
Build and Run
# Create a new project
dotnet new console -n ExampleProject --framework net10.0
# Add Aspose.Slides
dotnet add package Aspose.Slides
# Build
dotnet build --configuration Release --verbosity minimal
# Run
dotnet run
Project File (.csproj)
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Aspose.Slides" />
</ItemGroup>
</Project>
Environment
- .NET SDK 10.0 or higher
- NuGet package Aspose.Slides
- Each example is a standalone console application
Generated: 2026-09-17