public void SaveFile(MDFile md, bool saveAs = false) { // check exists // open file // write all lines // subscribe to file changes? string path = md.file; if (saveAs || path == null) { using (var sfd = new SaveFileDialog()) { sfd.InitialDirectory = path ?? Environment.CurrentDirectory; sfd.Filter = "Markdown *.md|*.md|All Files|*.*"; var res = sfd.ShowDialog(); if (res == DialogResult.OK) { path = sfd.FileName; } else { return; } } } md.Save(); // reload the file, enabling the watcher LoadFile(path, md); }