·5 min read
A .task note is a zip: one file for text and images, saved by swapping a temp file
I wanted a TaskPad note to carry its screenshots with it. A plain .txt file with  in it falls apart the moment you email it or move it out of its folder: the text arrives and the pictures stay behind. Commit ebfabf9 fixes that with a new extension, .task, and one new file, src/TaskFile.cs, 143 lines at the time of the commit.
- Project
- TaskPad
- Date
- Oct 2026
- Stack
- C#, WPF, System.IO.Compression
- Commit
- ebfabf9
The format
The class comment at the top of the file is the whole spec:
/// ".task" = one file holding a note and its images. It is a ZIP archive:
/// note.txt the note (plain TaskPad text, images referenced as )
/// images/... the pictures
/// taskpad format marker ("1")The note inside is still plain TaskPad text, the same lines the editor parses for checkboxes and tags. Only the image references are constrained: inside a .task they always look like images/name.png, relative to the archive root. That means the editor's existing image code could stay almost unchanged. The commit's changes to Images.cs are small: StoreDir and RefFor use the note's asset folder when there is one, and Resolve checks that folder before falling back to the folder next to the file.
A working copy while the note is open
The editor and the image renderer want real files on disk, not entries inside an archive. So Load unpacks the images into a cache folder and returns the text. The folder name comes from the note's path:
var hash = sha.ComputeHash(Encoding.UTF8.GetBytes(Path.GetFullPath(path).ToLowerInvariant()));
var id = BitConverter.ToString(hash, 0, 8).Replace("-", "").ToLowerInvariant();
return Path.Combine(Path.GetTempPath(), "TaskPad", "open", id);The same path always maps to the same folder, which is what session restore relies on: EnsureAssets looks for images/ there and only unpacks again if it is missing. Lower-casing the path matters on Windows, where C:\Notes\a.task and c:\notes\A.task are the same file. When the last tab closes, Doc.Dispose calls TaskFile.Discard, but only if the document is clean. An unsaved note keeps its working copy because the restore code needs it. A comment in CleanupLegacyCache says older versions kept these copies under %LOCALAPPDATA%\TaskPad\task-cache, and the new code deletes that folder at startup.
Saving: adopt, then pack
Users paste images from anywhere, so a note can reference C:\Users\...\Downloads\shot.png or an old images\ folder next to a .txt. Before packing, Adopt walks every image reference, copies the file into the note's own images/ folder and rewrites the reference:
using (doc.Document.RunUpdate())
foreach (var c in changes.OrderByDescending(c => c.Index))
doc.Document.Replace(c.Index, c.Length, c.Text);I collect all the changes first and apply them from the last offset to the first. Replacing a long absolute path with a short images/x.png shifts every later offset, and going backwards means an offset I recorded is still valid when I use it. RunUpdate makes the whole rewrite one undo step. If two different files share a name, the second becomes name-2.png; SameFile compares size first and then bytes, so adopting the same file twice does not create a duplicate.
Save then writes note.txt and only the images the text still references. Delete a picture from the note and it is gone from the archive at the next save, so the file does not grow forever. The compression levels are chosen per entry: the note uses Optimal, the images use NoCompression because PNG and JPEG are already compressed, and the marker is stored as is. The archive is written to <path>.saving and put in place with File.Replace, so a crash in the middle leaves the previous version intact.
The zero-byte file
The Explorer integration registers .task with a ShellNew entry of NullFile, which is how Windows creates a new empty file of that type. An empty file is not a valid ZIP, so the first open of a brand-new note would have failed. Load starts with an explicit guard:
if (new FileInfo(path).Length == 0) return ""; // brand-new empty fileThe context-menu "New TaskPad note" path avoids the problem differently: Shell.CreateNew calls TaskFile.CreateNew, which writes a real archive containing a dated heading and an empty checkbox.
The registration also writes only under HKCU, so no admin rights are needed, and EnsureTaskFiles claims the extension only if the registered command does not already point at an existing executable. A second copy of TaskPad does not steal the association from the first.
Entries that climb out
A ZIP entry name is attacker-controlled data, and .task files can arrive by email. Load only extracts entries that start with images/, then checks where the resolved path actually lands:
var target = Path.GetFullPath(Path.Combine(assetDir, e.FullName.Replace('/', '\\')));
if (!target.StartsWith(assetDir, StringComparison.OrdinalIgnoreCase)) continue; // no path tricksLooking at it again for this post, the check is a plain prefix comparison without a trailing separator. It is safe here only because every cache folder name is exactly 16 hex characters, so no sibling folder can share the prefix. I would add the separator rather than depend on that.
What I have not measured
Save rewrites the whole archive every time, including every image, and SameFile reads both files fully once the sizes match. For a note with a handful of screenshots that is invisible, but I have not timed it on a note with dozens of large images, and with auto-save on it runs often. If it ever shows up, the fix is to skip copying images whose entries have not changed.
The design choice I would repeat is keeping the note as plain text inside the archive. Any ZIP tool can open a .task file, and the text inside can be read by hand.
#csharp#wpf#file-format#zip
Keep reading
Have a project in mind?