From 7a7014cec3d70a58239298c8c8e022acf2b675b0 Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Sat, 28 Mar 2020 10:55:32 +0700 Subject: [PATCH] - adding SendTextFile to simplify sending csv or textfiles by code without saving them to harddrive --- TelegramBotBase/Sessions/DeviceSession.cs | 28 +++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/TelegramBotBase/Sessions/DeviceSession.cs b/TelegramBotBase/Sessions/DeviceSession.cs index bc6c697..0aad579 100644 --- a/TelegramBotBase/Sessions/DeviceSession.cs +++ b/TelegramBotBase/Sessions/DeviceSession.cs @@ -501,6 +501,34 @@ namespace TelegramBotBase.Sessions return m; } + /// + /// Generates a Textfile from scratch with the specified encoding. (Default is UTF8) + /// + /// + /// + /// Default is UTF8 + /// + /// + /// + /// + /// + public async Task SendTextFile(String filename, String textcontent, Encoding encoding = null, String caption = "", ButtonForm buttons = null, int replyTo = 0, bool disableNotification = false) + { + encoding = encoding ?? Encoding.UTF8; + + var ms = new MemoryStream(); + var sw = new StreamWriter(ms, encoding); + + sw.Write(textcontent); + sw.Flush(); + + var content = ms.ToArray(); + + var m = await SendDocument(filename, content, caption, buttons, replyTo, disableNotification); + + return m; + } + /// /// Sends an document ///