private static void DoCopyNote(Note note) { NoteClipboardData data = new NoteClipboardData { Name = note.Name, Text = note.DecryptedText, Tags = new List <string>(note.Tags) }; if (note.Files.Any()) { data.Files = new List <ClipboardFile>(); foreach (NoteFile noteFile in note.Files) { ClipboardFile file = new ClipboardFile { Name = noteFile.Name, Data = File.ReadAllBytes(noteFile.FullName), FileName = noteFile.FileName, MimeType = MimeTypeMap.GetMimeType(Path.GetExtension(noteFile.FileName)) }; data.Files.Add(file); } } DataFormat format = DataFormats.GetDataFormat(typeof(NoteClipboardData).FullName); IDataObject dataObj = new DataObject(); dataObj.SetData(format.Name, data, false); Clipboard.SetDataObject(dataObj, false); }
private static List <ClipboardFile> GetFilesFromFilePaths(List <string> paths) { List <ClipboardFile> files = new List <ClipboardFile>(); foreach (string path in paths) { ClipboardFile clipboardFile = GetFileFromFilePath(path); if (clipboardFile != null) { files.Add(clipboardFile); } } return(files); }
private static ClipboardFile GetFileFromFilePath(string path) { try { ClipboardFile clipboardFile = new ClipboardFile(); clipboardFile.Name = Path.GetFileName(path); clipboardFile.Data = Convert.ToBase64String(File.ReadAllBytes(path)); return(clipboardFile); } catch (Exception e) { Console.WriteLine("Could not read file from path: " + path + " error: " + e.Message); } return(null); }