Sirus.Anki.NET 2.1.3

dotnet add package Sirus.Anki.NET --version 2.1.3
                    
NuGet\Install-Package Sirus.Anki.NET -Version 2.1.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="Sirus.Anki.NET" Version="2.1.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Sirus.Anki.NET" Version="2.1.3" />
                    
Directory.Packages.props
<PackageReference Include="Sirus.Anki.NET" />
                    
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 Sirus.Anki.NET --version 2.1.3
                    
#r "nuget: Sirus.Anki.NET, 2.1.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.
#addin nuget:?package=Sirus.Anki.NET&version=2.1.3
                    
Install Sirus.Anki.NET as a Cake Addin
#tool nuget:?package=Sirus.Anki.NET&version=2.1.3
                    
Install Sirus.Anki.NET as a Cake Tool

Anki.NET

NuGet NuGet

Create and export Anki collections, decks, notes and cards from your C# applications.

var noteType = new AnkiNoteType(
    name: "Basic",
    cardTypes: new[] {
        new AnkiCardType(
            Name: "Card 1",
            Ordinal: 0,
            QuestionFormat: "{{Front}}",
            AnswerFormat: "{{Front}}<hr id=\"answer\">{{Back}}"
        )
    },
    fieldNames: new[] { "Front", "Back" }
);

var collection = new AnkiCollection();

var noteTypeId = collection.CreateNoteType(noteType);
var deckId = collection.CreateDeck("My Anki Deck");

collection.CreateNote(deckId, noteTypeId, "Hello", "Bonjour");

await AnkiFileWriter.WriteToFileAsync("MyCollection.apkg", collection);

Acknowledgement

Anki.NET is a fork form the the archived AnkiSharp project from Clement-Jean. Thanks a lot for the hard work!

This is a fork of Anki.NET by lysrt modified by jonnydee with .NET 9 support and better performanced on large collections.

Usage

AnkiCollection

Start by creating an AnkiCollection. To add notes to the collection, you need a notes model (AnkiNoteType), you can pass in the constructor, like this. A note can correspond to one or several cards, if their model has several card tempates ('AnkiCardType').

var cardTypes = new[]
{
    new AnkiCardType(
        "Forwards",
        0,
        "{{Front}}<br/>{{hint:Help}}",
        "{{Front}}<hr id=\"answer\">{{Back}}"
    ),
    new AnkiCardType(
        "Backwards",
        1,
        "{{Back}}<br/>{{hint:Help}}",
        "{{Back}}<hr id=\"answer\">{{Front}}"
    )
};

var noteType = new AnkiNoteType(
    "Basic (With hints)",
    cardTypes,
    new[] { "Front", "Back", "Help" }
);
        
var collection = new AnkiCollection();
var noteTypeId = collection.CreateNoteType(noteType);

AnkiDeck

var collection = new AnkiCollection();

var deckId = collection.CreateDeck("French vocabulary");

bool deckExists = collection.TryGetDeckById(deckId, out var deck);

AnkiNote

With the above AnkiNoteType (which has two card types), each added note will generate 2 different cards.

collection.CreateNote(deckId, notetypeId, "Hello", "Bonjour", "");
collection.CreateNote(deckId, noteTypeId, "House", "Maison", "Starts with \"M\"");

Set CSS

var noteType = new AnkiNoteType(
    name: "Basic",
    cardTypes: cardTypes,
    fieldNames: names,
    css: @".card{
        color: red;
    }",
);

Read AnkiCollection from .apkg file

AnkiCollection collection = await AnkiFileReader.ReadFromFileAsync("collection.apkg");

Write AnkiCollection to .apkg file

var collection = new AnkiCollection();
await AnkiFileWriter.WriteToFileAsync("MyCollection.apkg", collection);

Resources

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

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.1.3 174 14 days ago
2.1.1 126 16 days ago