Egov.Integrations.MDocs 10.0.3

Prefix Reserved
dotnet add package Egov.Integrations.MDocs --version 10.0.3
                    
NuGet\Install-Package Egov.Integrations.MDocs -Version 10.0.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Egov.Integrations.MDocs" Version="10.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Egov.Integrations.MDocs" Version="10.0.3" />
                    
Directory.Packages.props
<PackageReference Include="Egov.Integrations.MDocs" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Egov.Integrations.MDocs --version 10.0.3
                    
#r "nuget: Egov.Integrations.MDocs, 10.0.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Egov.Integrations.MDocs@10.0.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Egov.Integrations.MDocs&version=10.0.3
                    
Install as a Cake Addin
#tool nuget:?package=Egov.Integrations.MDocs&version=10.0.3
                    
Install as a Cake Tool

Egov.Integrations.MDocs

NuGet License: MIT

A high-performance .NET library for integrating with the MDocs document management service. It provides a robust client for uploading blobs, publishing documents, managing shares, and performing document transformations. Designed for services on the eGov platform, it leverages Egov.Extensions.Configuration for secure certificate-based authentication (mTLS).


Table of Contents


Features

  • Blob Management: Upload large files with automatic chunking (support for Streams, File Paths, and Byte Arrays).
  • Document Publishing: Create documents with owner-based permissions and metadata.
  • Sharing and Reservations: Securely share documents with other principals or reserve shares with access codes.
  • Document Transformation: Transform documents into various formats (e.g., PDF) using server-side templates.
  • Quota Monitoring: Track storage usage and limits for principals.
  • Certificate-based Auth: Seamless integration with Egov.Extensions.Configuration for mutual TLS (mTLS).
  • Async-first API: Fully asynchronous methods for all service operations.
  • Built for .NET 10+: Optimized for the latest .NET features and performance.

Prerequisites

  • .NET 10.0 or later
  • A valid service certificate for MDocs (PFX or PEM format)
  • Access to the MDocs service API
  • Egov.Extensions.Configuration for certificate management

Installation

Install the package from NuGet:

dotnet add package Egov.Integrations.MDocs

Or via the Package Manager Console:

Install-Package Egov.Integrations.MDocs

Configuration

Add the following sections to your appsettings.json:

{
  "MDocs": {
    "BaseAddress": "https://mdocs.api.example.com"
  },
  "Certificate": {
    "Path": "Files/Certificates/your-certificate.pfx",
    "Password": "your-certificate-password"
  }
}

The MDocs client automatically uses the certificate configured via Egov.Extensions.Configuration.


Usage

Register the certificate and the MDocs client in Program.cs:

using Egov.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

var builder = WebApplication.CreateBuilder(args);

// Register the system certificate (required for mTLS)
builder.Services.AddSystemCertificate(builder.Configuration.GetSection("Certificate"));

// Register the MDocs client
builder.Services.AddMDocsClient(builder.Configuration.GetSection("MDocs"));

var app = builder.Build();

Blob Management

Upload files to MDocs. Large files are automatically handled using chunked uploads.

public async Task<Guid> UploadFileAsync(IMDocsClient mdocsClient, string path)
{
    // Upload a PDF file
    Guid blobId = await mdocsClient.UploadBlobAsync(path, MDocsContentType.Pdf);
    return blobId;
}

Document Publishing

Transform an uploaded blob into a formal document with permissions.

public async Task PublishExampleAsync(IMDocsClient client, Guid blobId)
{
    var documents = new List<Document>
    {
        new Document
        {
            Name = "Annual Report 2025",
            Principal = new Uri("urn:egov:principal:1234567890123"),
            CreatedBy = new Uri("urn:egov:service:my-app"),
            Number = "AR-2025-001"
        }
    };

    var published = await client.PublishDocumentsAsync(blobId, documents);
    foreach (var doc in published)
    {
        Console.WriteLine($"Published: {doc.Name} with ID: {doc.Id}");
    }
}

Sharing and Reservations

Reserve a share and then use it when publishing a document.

public async Task ShareWithReservationAsync(IMDocsClient client, Guid blobId)
{
    // 1. Reserve a share (useful for generating QR codes/links before the file is ready)
    var reservation = await client.ReserveShareAsync(generateAccessCode: true);
    
    // 2. Publish with the reservation
    var document = new Document
    {
        Name = "Private Document",
        Principal = new Uri("urn:egov:principal:owner"),
        CreatedBy = new Uri("urn:egov:service:app"),
        Shares = new List<ShareRequest>
        {
            new ShareRequest 
            { 
                For = new Uri("urn:egov:principal:recipient"),
                Permission = Permission.Read,
                ReservedId = reservation.Id // Link to reservation
            }
        }
    };

    await client.PublishDocumentsAsync(blobId, new[] { document });
}

Document Transformation

Convert documents using predefined templates.

public async Task<Stream> TransformToPdfAsync(IMDocsClient client, Stream sourceJson)
{
    // Transform JSON data into a PDF using a specific document type template
    return await client.TransformDocumentAsync(
        sourceJson, 
        MDocsContentType.Json, 
        documentTypeCode: "OFFICIAL_LETTER", 
        format: TemplateContentType.Pdf
    );
}

Error Handling

The client library throws MDocsException for service-level errors, providing details about the failure:

Scenario Exception
Invalid API response (4xx, 5xx) MDocsException (contains Title, Status, and Errors)
Certificate not configured InvalidOperationException (during mTLS handshake)
Serialization issues JsonException
Cancellation requested OperationCanceledException

Testing

The solution includes a test project Egov.Integrations.MDocs.Tests built with xUnit.

Running the tests

dotnet test src/Egov.Integrations.MDocs.Tests

Contributing

Contributions are welcome! Please read CONTRIBUTING.md for guidelines.


Code of Conduct

This project adheres to the Contributor Covenant Code of Conduct.


AI Assistance

This repository contains an AGENTS.md file with instructions and context for AI coding agents to assist in development.


License

This project is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Egov.Integrations.MDocs:

Package Downloads
Egov.Fod.BackComponents

Standard backend components for FOD integrations including MDocs, MNotify, MSign, and MPower.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
10.0.3 161 4/10/2026