Anki.NET 1.0.0

.NET 6.0
dotnet add package Anki.NET --version 1.0.0
NuGet\Install-Package Anki.NET -Version 1.0.0
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="Anki.NET" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Anki.NET --version 1.0.0
#r "nuget: Anki.NET, 1.0.0"
#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.
// Install Anki.NET as a Cake Addin
#addin nuget:?package=Anki.NET&version=1.0.0

// Install Anki.NET as a Cake Tool
#tool nuget:?package=Anki.NET&version=1.0.0

Anki.NET

NuGet NuGet

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

var noteType = new AnkiNoteType(1, "Basic")
{
    Fields = new[] { "Front", "Back" },
    CardTypes = new[]
    {
        new AnkiCardType
        (
            Name: "Card 1",
            Ordinal: 0,
            QuestionFormat: "{{Front}}",
            AnswerFormat: "{{Front}}<hr id=\"answer\">{{Back}}"
        ),
                
    }
};
AnkiCollection collection = new AnkiCollection(noteType);
AnkiDeck deck = collection.AddDeck("My Anki Deck");

collection.AddNote(deck, noteType, "Hello", "Bonjour");

await new AnkiFileWriter().WriteCollectionToFile(collection, "/", "MyCollection.apkg");

Acknowledgement

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

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 noteType = new AnkiNoteType(1, "Basic (With hints)")
{
    Fields = new[] { "Front", "Back", "Help" },
    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 collection = new AnkiCollection(noteType);

AnkiDeck

var collection = new AnkiCollection(noteType);

var myDeck = collection.AddDeck("French vocabulary");

var defaultDeck = collection.GetDeckById(1);
var myDeckAgain = collection.GetDeckById(myDeck.Id);

AnkiNote

With the above AnkiNoteType, each added note will generate 2 different cards.

collection.AddNote(defaultDeck, noteType, "Hello", "Bonjour", "");
collection.AddNote(defaultDeck, noteType, "House", "Maison", "Starts with "M");

Set CSS

var noteType = new AnkiNoteType(1, "Basic (with CSS)")
{
    Css = @".card{
        color: red;
    }",
    // ... 
};

Read AnkiCollection from .apkg file

var collection = await AnkiFileReader.ReadCollection(_path);

Resources

Product Versions
.NET net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
Compatible target framework(s)
Additional computed target framework(s)
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
1.0.0 151 12/28/2022
0.1.2 264 8/28/2022
0.1.1 246 8/28/2022