Sending pdf file with C# Telegram Bot Api

Viewed 24

I have a field called TELEGRAM and when it is clicked, I am trying to share the end of day report on the screen as a pdf via telegram with the help of a bot. I am recording and deleting the file in the background. But before I delete it, I want it to send this pdf file via telegram. But it only sends with the name of the pdf file. It does not send as a document.

void barItem_ItemClick(object sender, ItemClickEventArgs e)
    {
        DateTime Tarih = DateTime.Today.Date;
        if (vwMain.GetFocusedRowCellValue(clnUHTarih) != null)
            DateTime.TryParse(vwMain.GetFocusedRowCellValue(clnUHTarih).ToString(), out Tarih);

        //MessageBox.Show("Item is clicked!");

        PdfExportOptions pdfExportOptions = new PdfExportOptions()
        {
            PdfACompatibility = PdfACompatibility.PdfA1b
        };

        string pdfExportFile = @"C:\ayvalık\" + Convert.ToString(DateTime.Now).Replace(".","").Replace(":","").Replace(" ", "_") + ".pdf";
        // Export the report.
        rprGunSonu rpr = new rprGunSonu(pConn, Tarih.Date, clsAyarlar.SubeID);
        pt = new ReportPrintTool(rpr);
        rpr.ExportToPdf(pdfExportFile, pdfExportOptions);


         string urlString = "https://api.telegram.org/bot{0}/sendMessage?chat_id={1}&text={2}";
         string apiToken = "5302720676:AAGgH0IoYegOz8D7h_8PrB45aONhphcaxp4";
         string chatId = "@nyd_deneme";
         string fileContent = string.Empty;
         string filePath = string.Empty;
         object gridControl1;

        string gonderilecekDosya = pdfExportFile.ToString();
        string text = gonderilecekDosya;
        urlString = String.Format(urlString, apiToken, chatId, text);
        WebRequest request = WebRequest.Create(urlString);
        Stream rs = request.GetResponse().GetResponseStream();
        StreamReader reader = new StreamReader(rs);
        string line = "";
        StringBuilder sb = new StringBuilder();
        while (line != null)
        {
            line = reader.ReadLine();
            if (line != null)
                sb.Append(line);
        }
        string response = sb.ToString();

    MessageBox.Show("Telegram Mesajı Gönderildi.");

        string klasorYolu = @"C:\ayvalık\"; // bu klasörde dosya aranacak ve tüm alt klasörlerinde
        string silinecekDosya = pdfExportFile.ToString();   // silinecek dosyanın adı
        string[] dosyaList = Directory.GetFiles(klasorYolu);
        foreach (string _file in dosyaList)
        {
            //burada dosya siliniyor.
            File.Delete(_file);
        }

    }
}
0 Answers
Related