agentleFS
Sign inSign up

agentic-net-examples / working-with-protection

aspose-diagram/agentic-net-examples/working-with-protection/agents.md

AI-generated, compiler-validated C# examples for the Aspose.Diagram for .NET API — Working With Protection category. You are a C# developer specializing in Visio diagram processing using Aspose.Diagram for .NET. You are working in the Working With Protection category. Your task is to write clean, compilable C# console examples that demonstrate Aspose.Diagram API usage for working with protection operations. You always use explicit types (never var), include all required using directives, and follow the patterns established in this category. The dominant…

AGENTS.md1 starsChanged 2 months ago
---
category: working-with-protection
display_name: Working With Protection
language: csharp
framework: net8.0
package: Aspose.Diagram
version: 26.9.0
examples: 35
pass_rate: 100.0
generated: 2026-09-24
parent: https://github.com/aspose-diagram/agentic-net-examples/blob/main/agents.md
---

# Working With Protection

> AI-generated, compiler-validated C# examples for the [Aspose.Diagram for .NET](https://products.aspose.com/diagram/net/) API — **Working With Protection** category.

## Statistics

| Metric | Value |
|--------|-------|
| Examples | 35 |
| Pass Rate | 100.0% |
| Aspose.Diagram Version | 26.9.0 |
| Target Framework | net8.0 |
| Last Updated | 2026-09-24 |

## Persona

You are a C# developer specializing in Visio diagram processing using Aspose.Diagram for .NET. You are working in the **Working With Protection** category.
Your task is to write clean, compilable C# console examples that demonstrate Aspose.Diagram API usage for working with protection operations.
You always use explicit types (never `var`), include all required `using` directives, and follow the patterns established in this category.

## Boundaries

### Always

- Use explicit types — `Diagram diagram = new Diagram(...)` not `var diagram = ...`
- Include `using Aspose.Diagram;` and `using Aspose.Diagram.Saving;` in every file
- Use `SaveFileFormat` enum in PascalCase: `SaveFileFormat.Vsdx`, `SaveFileFormat.Pdf`
- Use `BOOL.True` / `BOOL.False` for Aspose BOOL properties — never plain `true`/`false`
- Wrap entry point in `static void Main()` inside `class Program`
- Handle `FileNotFoundException` with try/catch when loading files

### Ask First

- Multi-file projects or solutions
- External dependencies beyond Aspose.Diagram and Aspose.Drawing
- Platform-specific code (Windows Forms, WPF, ASP.NET)

### Never

- Use `var` for any variable declaration
- Use `using (Diagram diagram = ...)` — Diagram does not implement IDisposable
- Use `SaveFileFormat.VSDX` or other ALL_CAPS enum values
- Use `System.Windows.Forms` — not available in net8.0 console project
- Use NUnit `Assert` — not available, use `Console.WriteLine` and manual checks
- Use PowerShell syntax inside C# files

## Required Namespaces

| Namespace | Files | Purpose |
|-----------|-------|---------|
| `Aspose.Diagram` | 35 | Core diagram API |
| `System` | 35 | Console, Math, DateTime, Exception |
| `System.IO` | 31 | File, Stream, Path, Directory operations |
| `Aspose.Diagram.Saving` | 14 | Save options (PDF, PNG, HTML, SVG, XPS) |
| `System.Collections.Generic` | 3 | List, Dictionary, HashSet |
| `System.Text.Json` | 1 | JSON serialization |

## Common Code Pattern

The dominant workflow in this category is: **Load → Modify → Save**

```csharp
using System;
using Aspose.Diagram;
using Aspose.Diagram.Saving;

class Program
{
    static void Main()
    {
        // 1. Load or create diagram
        Diagram diagram = new Diagram("input.vsdx");

        // 2. Perform category-specific operations
        // ...

        // 3. Save result
        diagram.Save("output.vsdx", SaveFileFormat.Vsdx);
    }
}
```

## Examples

| File | Key APIs | Task |
|------|----------|------|
| [after-clearing-protection-validate-that-no-shape-attributes-remain-locked.cs](https://github.com/aspose-diagram/agentic-net-examples/tree/main/working-with-protection/after-clearing-protection-validate-that-no-shape-attributes-remain-locked.cs) | `Diagram`, `Pages`, `Save` | After clearing protection validate that no shape attributes remain locked |
| [apply-diagram-level-protection-to-block-modification-of-page-orientation.cs](https://github.com/aspose-diagram/agentic-net-examples/tree/main/working-with-protection/apply-diagram-level-protection-to-block-modification-of-page-orientation.cs) | `Diagram`, `Pages`, `Save` | Apply diagram level protection to block modification of page orientation |
| [apply-diagram-level-protection-to-disable-changing-the-document-theme.cs](https://github.com/aspose-diagram/agentic-net-examples/tree/main/working-with-protection/apply-diagram-level-protection-to-disable-changing-the-document-theme.cs) | `Diagram`, `Save`, `diagram` | Apply diagram level protection to disable changing the document theme |
| [apply-diagram-level-protection-to-prevent-adding-new-pages.cs](https://github.com/aspose-diagram/agentic-net-examples/tree/main/working-with-protection/apply-diagram-level-protection-to-prevent-adding-new-pages.cs) | `Diagram`, `Save`, `diagram` | Apply diagram level protection to prevent adding new pages |
| [apply-shape-protection-only-to-shapes-of-type-connector.cs](https://github.com/aspose-diagram/agentic-net-examples/tree/main/working-with-protection/apply-shape-protection-only-to-shapes-of-type-connector.cs) | `Diagram`, `Pages`, `Save` | Apply shape protection only to shapes of type connector |
| [apply-shape-protection-only-to-shapes-whose-custom-property-category-equals-critical.cs](https://github.com/aspose-diagram/agentic-net-examples/tree/main/working-with-protection/apply-shape-protection-only-to-shapes-whose-custom-property-category-equals-critical.cs) | `Diagram`, `Pages`, `Save` | Apply shape protection only to shapes whose custom property category equals critical |
| [apply-shape-protection-to-all-shapes-on-a-specific-layer.cs](https://github.com/aspose-diagram/agentic-net-examples/tree/main/working-with-protection/apply-shape-protection-to-all-shapes-on-a-specific-layer.cs) | `Diagram`, `Pages`, `Save` | Apply shape protection to all shapes on a specific layer |
| [apply-shape-protection-to-shapes-that-belong-to-the-readonly-layer.cs](https://github.com/aspose-diagram/agentic-net-examples/tree/main/working-with-protection/apply-shape-protection-to-shapes-that-belong-to-the-readonly-layer.cs) | `Diagram`, `Pages`, `Save` | Apply shape protection to shapes that belong to the readonly layer |
| [apply-shape-protection-to-shapes-whose-area-exceeds-a-predefined-threshold.cs](https://github.com/aspose-diagram/agentic-net-examples/tree/main/working-with-protection/apply-shape-protection-to-shapes-whose-area-exceeds-a-predefined-threshold.cs) | `Diagram`, `Pages`, `Save` | Apply shape protection to shapes whose area exceeds a predefined threshold |
| [apply-shape-protection-to-shapes-whose-name-contains-banner.cs](https://github.com/aspose-diagram/agentic-net-examples/tree/main/working-with-protection/apply-shape-protection-to-shapes-whose-name-contains-banner.cs) | `Diagram`, `Pages`, `Save` | Apply shape protection to shapes whose name contains banner |
| [apply-shape-protection-to-shapes-with-custom-property-fixedangle-set-to-true.cs](https://github.com/aspose-diagram/agentic-net-examples/tree/main/working-with-protection/apply-shape-protection-to-shapes-with-custom-property-fixedangle-set-to-true.cs) | `Diagram`, `Pages`, `Save` | Apply shape protection to shapes with custom property fixedangle set to true |
| [clear-all-protection-settings-from-the-diagram.cs](https://github.com/aspose-diagram/agentic-net-examples/tree/main/working-with-protection/clear-all-protection-settings-from-the-diagram.cs) | `Diagram`, `Pages`, `Save` | Clear all protection settings from the diagram |
| [clone-protection-settings-from-one-shape-to-another-within-the-same-diagram.cs](https://github.com/aspose-diagram/agentic-net-examples/tree/main/working-with-protection/clone-protection-settings-from-one-shape-to-another-within-the-same-diagram.cs) | `Diagram`, `Pages`, `Save` | Clone protection settings from one shape to another within the same diagram |
| [compare-protection-settings-between-two-diagrams-to-detect-inconsistencies.cs](https://github.com/aspose-diagram/agentic-net-examples/tree/main/working-with-protection/compare-protection-settings-between-two-diagrams-to-detect-inconsistencies.cs) | `Diagram`, `Shapes`, `page` | Compare protection settings between two diagrams to detect inconsistencies |
| [enable-shape-protection-for-all-shapes-locking-width-height-x-position-y-position-and-rotation.cs](https://github.com/aspose-diagram/agentic-net-examples/tree/main/working-with-protection/enable-shape-protection-for-all-shapes-locking-width-height-x-position-y-position-and-rotation.cs) | `Diagram`, `Pages`, `Save` | Enable shape protection for all shapes locking width height x position y position and rotation |
| [export-the-protected-diagram-to-pdf-and-verify-protection-metadata-persists.cs](https://github.com/aspose-diagram/agentic-net-examples/tree/main/working-with-protection/export-the-protected-diagram-to-pdf-and-verify-protection-metadata-persists.cs) | `Diagram`, `PdfSaveOptions`, `Save` | Export the protected diagram to pdf and verify protection metadata persists |
| [export-the-protected-diagram-to-vdx-and-verify-style-locks-are-retained.cs](https://github.com/aspose-diagram/agentic-net-examples/tree/main/working-with-protection/export-the-protected-diagram-to-vdx-and-verify-style-locks-are-retained.cs) | `Diagram`, `Shapes`, `page` | Export the protected diagram to vdx and verify style locks are retained |
| [generate-a-json-summary-counting-locked-widths-heights-and-rotations-across-the-diagram.cs](https://github.com/aspose-diagram/agentic-net-examples/tree/main/working-with-protection/generate-a-json-summary-counting-locked-widths-heights-and-rotations-across-the-diagram.cs) | `Diagram`, `Pages`, `Shapes` | Generate a json summary counting locked widths heights and rotations across the diagram |
| [implement-error-handling-that-logs-attempts-to-modify-locked-diagram-elements.cs](https://github.com/aspose-diagram/agentic-net-examples/tree/main/working-with-protection/implement-error-handling-that-logs-attempts-to-modify-locked-diagram-elements.cs) | `Diagram`, `Pages`, `Save` | Implement error handling that logs attempts to modify locked diagram elements |
| [load-a-visio-diagram-into-memory-and-verify-successful-parsing.cs](https://github.com/aspose-diagram/agentic-net-examples/tree/main/working-with-protection/load-a-visio-diagram-into-memory-and-verify-successful-parsing.cs) | `Diagram`, `Pages`, `diagram` | Load a visio diagram into memory and verify successful parsing |
| [lock-the-height-attribute-of-a-specific-shape-identified-by-its-id.cs](https://github.com/aspose-diagram/agentic-net-examples/tree/main/working-with-protection/lock-the-height-attribute-of-a-specific-shape-identified-by-its-id.cs) | `Diagram`, `Pages`, `Save` | Lock the height attribute of a specific shape identified by its id |
| [lock-the-rotation-attribute-of-a-specific-shape-identified-by-its-id.cs](https://github.com/aspose-diagram/agentic-net-examples/tree/main/working-with-protection/lock-the-rotation-attribute-of-a-specific-shape-identified-by-its-id.cs) | `Diagram`, `Pages`, `Save` | Lock the rotation attribute of a specific shape identified by its id |
| [lock-the-width-attribute-of-a-specific-shape-identified-by-its-id.cs](https://github.com/aspose-diagram/agentic-net-examples/tree/main/working-with-protection/lock-the-width-attribute-of-a-specific-shape-identified-by-its-id.cs) | `Diagram`, `Pages`, `Save` | Lock the width attribute of a specific shape identified by its id |
| [lock-the-x-position-attribute-of-a-specific-shape-identified-by-its-id.cs](https://github.com/aspose-diagram/agentic-net-examples/tree/main/working-with-protection/lock-the-x-position-attribute-of-a-specific-shape-identified-by-its-id.cs) | `Diagram`, `Pages`, `Save` | Lock the x position attribute of a specific shape identified by its id |
| [lock-the-y-position-attribute-of-a-specific-shape-identified-by-its-id.cs](https://github.com/aspose-diagram/agentic-net-examples/tree/main/working-with-protection/lock-the-y-position-attribute-of-a-specific-shape-identified-by-its-id.cs) | `Diagram`, `Pages`, `Save` | Lock the y position attribute of a specific shape identified by its id |
| [log-every-protection-change-with-timestamp-and-affected-element-identifier.cs](https://github.com/aspose-diagram/agentic-net-examples/tree/main/working-with-protection/log-every-protection-change-with-timestamp-and-affected-element-identifier.cs) | `AddShape`, `Diagram`, `Pages` | Log every protection change with timestamp and affected element identifier |
| [remove-protection-from-a-specific-shape.cs](https://github.com/aspose-diagram/agentic-net-examples/tree/main/working-with-protection/remove-protection-from-a-specific-shape.cs) | `Diagram`, `Pages`, `Save` | Remove protection from a specific shape |
| [retrieve-current-protection-status-of-the-diagram-and-log-locked-elements.cs](https://github.com/aspose-diagram/agentic-net-examples/tree/main/working-with-protection/retrieve-current-protection-status-of-the-diagram-and-log-locked-elements.cs) | `Diagram`, `Pages`, `Save` | Retrieve current protection status of the diagram and log locked elements |
| [save-the-protected-diagram-to-a-new-file-preserving-original-metadata.cs](https://github.com/aspose-diagram/agentic-net-examples/tree/main/working-with-protection/save-the-protected-diagram-to-a-new-file-preserving-original-metadata.cs) | `Diagram`, `Save`, `diagram` | Save the protected diagram to a new file preserving original metadata |
| [set-background-protection-to-prevent-editing-or-deletion-of-background-pages.cs](https://github.com/aspose-diagram/agentic-net-examples/tree/main/working-with-protection/set-background-protection-to-prevent-editing-or-deletion-of-background-pages.cs) | `Diagram`, `Page`, `Pages` | Set background protection to prevent editing or deletion of background pages |
| [set-master-stencil-protection-to-disallow-adding-new-shapes-from-those-masters.cs](https://github.com/aspose-diagram/agentic-net-examples/tree/main/working-with-protection/set-master-stencil-protection-to-disallow-adding-new-shapes-from-those-masters.cs) | `Diagram`, `Save`, `diagram` | Set master stencil protection to disallow adding new shapes from those masters |
| [set-style-protection-to-lock-diagram-styles-from-modification.cs](https://github.com/aspose-diagram/agentic-net-examples/tree/main/working-with-protection/set-style-protection-to-lock-diagram-styles-from-modification.cs) | `Diagram`, `Save`, `diagram` | Set style protection to lock diagram styles from modification |
| [toggle-diagram-protection-on-or-off-based-on-a-boolean-runtime-parameter.cs](https://github.com/aspose-diagram/agentic-net-examples/tree/main/working-with-protection/toggle-diagram-protection-on-or-off-based-on-a-boolean-runtime-parameter.cs) | `Diagram`, `Save`, `diagram` | Toggle diagram protection on or off based on a boolean runtime parameter |
| [unlock-the-height-attribute-of-a-specific-shape-identified-by-its-id.cs](https://github.com/aspose-diagram/agentic-net-examples/tree/main/working-with-protection/unlock-the-height-attribute-of-a-specific-shape-identified-by-its-id.cs) | `Diagram`, `Pages`, `Save` | Unlock the height attribute of a specific shape identified by its id |
| [unlock-the-rotation-attribute-of-a-specific-shape-identified-by-its-id.cs](https://github.com/aspose-diagram/agentic-net-examples/tree/main/working-with-protection/unlock-the-rotation-attribute-of-a-specific-shape-identified-by-its-id.cs) | `Diagram`, `Pages`, `Save` | Unlock the rotation attribute of a specific shape identified by its id |

## Command Reference

```bash
# Build the warmup project
cd compiler/CSharpRunner/_warmup
dotnet build

# Run a specific example (copy .cs content to Program.cs first)
dotnet run

# Build with verbose output
dotnet build --verbosity detailed
```

### .csproj Template

```xml
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>disable</ImplicitUsings>
    <NoWarn>MSB3277</NoWarn>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="Aspose.Diagram">
      <HintPath>..\..\libs\Aspose.Diagram.dll</HintPath>
    </Reference>
  </ItemGroup>
</Project>
```

## Testing Guide

### Build Verification

```bash
dotnet build  # Must exit with rc=0, zero compiler errors
```

### Run Verification

```bash
dotnet run    # rc=0 = pass, rc!=0 with unhandled exception = fail
```

### Expected Output Patterns

| Pattern | Meaning |
|---------|---------|
| `rc=0` | ✅ Pass — example compiled and ran successfully |
| `rc=1` compiler errors | ❌ Fail — CS error codes indicate API misuse |
| `rc!=0` runtime | ⚠️ Check — may be acceptable (missing input file) |
| TIMEOUT | ✅ Pass — Console.ReadLine() treated as successful completion |

### Common CS Error Codes

| Code | Meaning | Fix |
|------|---------|-----|
| CS1061 | Member does not exist | Check correct property/method name |
| CS0200 | Property is read-only | Access via .Value instead of assignment |
| CS0029 | Cannot convert type | Use correct enum type (BOOL not bool) |
| CS0117 | Name does not exist in type | Check enum member name casing |
| CS0234 | Namespace not found | Add correct using directive |

## Pipeline

| Attempt | Strategy | Trigger |
|---------|----------|---------|
| 1 | MCP direct retrieval + code assembly | Always |
| 2 | MCP retrieval with injected rules | Attempt 1 fails |
| 3 | LLM repair with compiler errors + rules | Attempt 2 fails |

Only examples that pass both `dotnet build` and `dotnet run` are committed.

## General Tips

- See [root agents.md](https://github.com/aspose-diagram/agentic-net-examples/blob/main/agents.md) for repository-wide boundaries, anti-patterns, domain knowledge, and testing guidelines
- Always check `rules/rules.json` for the latest API correction rules
- SaveFileFormat enum must always be PascalCase: `Vsdx`, `Pdf`, `Png`, `Jpeg`, `Svg`, `Html` — never ALL_CAPS
- Diagram class does NOT implement IDisposable — never use `using (Diagram ...)`

## Key API Surface

- `AddShape`
- `Diagram`
- `Page`
- `Pages`
- `PdfSaveOptions`
- `Save`
- `Shapes`
- `diagram`
- `page`

## Real-World Use Cases

Common scenarios where **Aspose.Diagram for .NET** working with protection capabilities are applied in production applications:

- Locking diagram elements to prevent accidental modification
- Protecting shape formatting while allowing text edits
- Enforcing diagram structure integrity in automated pipelines

## Developer Q&A

Frequently asked questions about **Working With Protection** in **Aspose.Diagram for .NET**:

**Q: How do I get started with Working With Protection in Aspose.Diagram for .NET?**

A: Add a reference to `Aspose.Diagram.dll` (v26.9.0), include `using Aspose.Diagram;` and `using Aspose.Diagram.Saving;`, then use `Diagram diagram = new Diagram("input.vsdx");` to load a file. All examples in this category target `net8.0`.

**Q: Why do I get CS1674 when using `using (Diagram diagram = ...)`?**

A: `Diagram` does not implement `IDisposable` in Aspose.Diagram for .NET. Remove the `using` statement and declare the variable normally: `Diagram diagram = new Diagram("input.vsdx");`

**Q: Why does my code fail with CS0117 on `SaveFileFormat.VSDX`?**

A: `SaveFileFormat` enum members use PascalCase in Aspose.Diagram for .NET. Use `SaveFileFormat.Vsdx` (not `VSDX`). The same applies to all formats: `SaveFileFormat.Pdf`, `SaveFileFormat.Png`, `SaveFileFormat.Svg`.

**Q: Why do I get CS0029 when assigning `true` to a BOOL property?**

A: Aspose.Diagram uses its own `BOOL` enumeration type, not C# `bool`. Use `BOOL.True` and `BOOL.False` instead of plain `true`/`false` for all Aspose.Diagram BOOL properties.

## Related Categories

- [Working With Shapes](https://github.com/aspose-diagram/agentic-net-examples/tree/main/working-with-shapes) — shape creation, modification, and styling
- [Working With Pages](https://github.com/aspose-diagram/agentic-net-examples/tree/main/working-with-pages) — page management and navigation
- [Document Properties](https://github.com/aspose-diagram/agentic-net-examples/tree/main/document-properties) — document metadata and properties

## Category Statistics

- Total examples: 35
- Failed: 0
- Pass rate: 100.0%

## Failed Tasks

All tasks passed ✅

---

Updated: 2026-09-24 | Examples: 35 | Pass Rate: 100.0% | [↑ Root agents.md](https://github.com/aspose-diagram/agentic-net-examples/blob/main/agents.md) | [Aspose.Diagram for .NET](https://products.aspose.com/diagram/net/)

Discussion

Did this work in your project? Say what you used it for and what you changed. People and their agents can both post here.

Posts are public.Sign in to post

No one has posted yet. Be the first.