Click here to Skip to main content
15,881,852 members
Home / Discussions / C#
   

C#

 
AnswerRe: How do I add text via c# to an OPEN Excel Workbook? Pin
OriginalGriff18-May-22 19:18
mveOriginalGriff18-May-22 19:18 
AnswerRe: How do I add text via c# to an OPEN Excel Workbook? Pin
Richard Deeming18-May-22 23:46
mveRichard Deeming18-May-22 23:46 
GeneralRe: How do I add text via c# to an OPEN Excel Workbook? Pin
Eddy Vluggen20-May-22 8:13
professionalEddy Vluggen20-May-22 8:13 
AnswerRe: How do I add text via c# to an OPEN Excel Workbook? Pin
RedDk20-May-22 9:54
RedDk20-May-22 9:54 
JokeRe: How do I add text via c# to an OPEN Excel Workbook? Pin
Richard Andrew x6421-May-22 4:05
professionalRichard Andrew x6421-May-22 4:05 
GeneralRe: How do I add text via c# to an OPEN Excel Workbook? Pin
Richard MacCutchan21-May-22 6:07
mveRichard MacCutchan21-May-22 6:07 
GeneralRe: How do I add text via c# to an OPEN Excel Workbook? Pin
RedDk21-May-22 7:50
RedDk21-May-22 7:50 
QuestionSend message to Microsoft teams group via connector Pin
sdesilets18-May-22 8:40
sdesilets18-May-22 8:40 
Hello everybody, I pretty new to programming, what I want to do is a C# program that will send a message to a Microsoft teams group via a webhook connector of this group.

I was able to achieve it with a Desktop code(with form),but I need it to be a console program, I have pretty much copy/paste the code from my Desktop project to my console project, but there something that don't work. Here is my code from my desktop project:
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;

using System.Threading.Tasks;
using System.Windows.Forms;

namespace test_team_2
{
    public partial class Form1 : Form
    {
        string[] cmdLineMe = Environment.GetCommandLineArgs();
        string webhookPdfTermine = "uri to my team groups;
        HttpClient client = new HttpClient();
        Message body = new Message();
        string finalMessage = "";


        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            for (int i = 0; i < cmdLineMe.Length; i++)
            {
                finalMessage = cmdLineMe[i];
            }

            sendMsg();

        }

        public class Message
        {
            public string text { get; set; }
        }

        private async Task SendMsgAsync()
        {

            MessageBox.Show(finalMessage);
            client.BaseAddress = new Uri(webhookPdfTermine);
            body.text = finalMessage;
            string serializeJson = JsonSerializer.Serialize(body);
            StringContent content = new StringContent(serializeJson, Encoding.UTF8, "application/json");
            _ = await client.PostAsync(client.BaseAddress, content);
        }

        void sendMsg()
        {
            
            _ = SendMsgAsync();

        }

    }
}


And here is my code for my console project:

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text.Json;

namespace TeamBots
{
    class Program
    {
        string[] cmdLineMe = Environment.GetCommandLineArgs();
        string webhookPdfTermine = "uri to my team groups";
        HttpClient client = new HttpClient();
        Message body = new Message();
        string finalMessage = "";

        static void Main(string[] args)
        {
            Program myprog  = new Program(); 

            for (int i = 0; i < myprog.cmdLineMe.Length; i++)
            {

                myprog.finalMessage = myprog.cmdLineMe[i];
            }


            myprog.sendMsg(); 
        }

        private async Task SendMsgAsync()
        {

            Console.WriteLine(finalMessage);
            client.BaseAddress = new Uri(webhookPdfTermine);
            body.text = finalMessage;
            string serializeJson = JsonSerializer.Serialize(body);
            StringContent content = new StringContent(serializeJson, Encoding.UTF8, "application/json");
            _ = await client.PostAsync(client.BaseAddress, content);
        }

        void sendMsg()
        {
          
            _ = SendMsgAsync();

        }




        public class Message
        {
            public string text { get; set; }
        }
    }
}


Like I said before, I pretty new to programming, the code was taken from website there and there...

If anyone can help it will be very appreciated.

Thank you

modified 18-May-22 15:09pm.

AnswerRe: Send message to Microsoft teams group via connector Pin
lmoelleb19-May-22 0:48
lmoelleb19-May-22 0:48 
GeneralRe: Send message to Microsoft teams group via connector Pin
sdesilets19-May-22 4:44
sdesilets19-May-22 4:44 
QuestionAnyone have experience porting Wonderware scripting to C#.net? Pin
Bruce Armstrong 202218-May-22 6:36
Bruce Armstrong 202218-May-22 6:36 
AnswerRe: Anyone have experience porting Wonderware scripting to C#.net? Pin
Eddy Vluggen20-May-22 4:11
professionalEddy Vluggen20-May-22 4:11 
QuestionIs there any difference in performance when you add a huge amount of data into the database using EF Core (row by row) or using SQL Server stored procedures? Pin
Code4Ever18-May-22 6:25
Code4Ever18-May-22 6:25 
AnswerRe: Is there any difference in performance when you add a huge amount of data into the database using EF Core (row by row) or using SQL Server stored procedures? Pin
Gerry Schmitz18-May-22 7:34
mveGerry Schmitz18-May-22 7:34 
AnswerRe: Is there any difference in performance when you add a huge amount of data into the database using EF Core (row by row) or using SQL Server stored procedures? Pin
Victor Nijegorodov18-May-22 9:27
Victor Nijegorodov18-May-22 9:27 
QuestionHZH_Controls.Controls.UCTextBoxEx Cast Object Error Problem Pin
Eddie You17-May-22 14:15
Eddie You17-May-22 14:15 
AnswerRe: HZH_Controls.Controls.UCTextBoxEx Cast Object Error Problem Pin
Richard MacCutchan17-May-22 21:26
mveRichard MacCutchan17-May-22 21:26 
GeneralRe: HZH_Controls.Controls.UCTextBoxEx Cast Object Error Problem Pin
Eddie You17-May-22 21:41
Eddie You17-May-22 21:41 
AnswerRe: HZH_Controls.Controls.UCTextBoxEx Cast Object Error Problem Pin
Richard Deeming17-May-22 21:27
mveRichard Deeming17-May-22 21:27 
GeneralRe: HZH_Controls.Controls.UCTextBoxEx Cast Object Error Problem Pin
Eddie You17-May-22 21:46
Eddie You17-May-22 21:46 
QuestionUsing Token in a WCF Pin
Luis M. Rojas16-May-22 6:07
Luis M. Rojas16-May-22 6:07 
QuestionSolved!!! Invalid expression term 'uint' Pin
mbah obiora14-May-22 22:41
mbah obiora14-May-22 22:41 
AnswerRe: Invalid expression term 'uint' Pin
OriginalGriff15-May-22 0:09
mveOriginalGriff15-May-22 0:09 
GeneralRe: Invalid expression term 'uint' Pin
mbah obiora15-May-22 1:54
mbah obiora15-May-22 1:54 
GeneralRe: Invalid expression term 'uint' Pin
OriginalGriff15-May-22 2:05
mveOriginalGriff15-May-22 2:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.