Re: How do I write a simple c# code in power automate
I was going to say you might be able to do it through Run PowerShell Script...this is what GPT had to say:
In Power Automate, the direct equivalent of writing C# code in a "code stage" as you might in other RPA tools like Blue Prism or UiPath isn't available in the same way. Power Automate focuses more on low-code, no-code solutions primarily using pre-built connectors and actions to integrate different services. However, there are a couple of ways you can integrate C# code or similar logic into your Power Automate flows:
-
Power Automate Desktop: This tool allows you to automate desktop and web applications on a Windows machine. It includes a "Run PowerShell script" action, which you can use to execute scripts that may interact with C# assemblies or use inline C# code with Add-Type cmdlet. However, this is limited and not as direct as using C#.
-
Azure Functions: You can write your C# code in an Azure Function and then call this function from Power Automate using the HTTP action. This is a powerful way to integrate custom code, as Azure Functions support multiple languages, including C#. This method involves writing your C# logic as a function in Azure, deploying it, and then invoking this function via HTTP requests.
-
Custom Connectors: If you have repetitive C# logic that you need to use across multiple flows, you might consider encapsulating this logic into a custom connector. Custom connectors in Power Automate can be created to wrap any REST API, which you could host yourself (e.g., as an Azure Function or another cloud service). This allows you to write the logic in C#, expose it through an API, and then use it in your flows.
-
HTTP Actions: Similar to using Azure Functions but more generic, you can host your C# code on any server that exposes it via HTTP(S) and call it using the HTTP action in Power Automate. This method requires you to manage the hosting and availability of your API.
Here's a quick example of how you might set up a simple Azure Function in C# that you can call from Power Automate:
Step 1: Create an Azure Function
- Write a C# function that performs your desired task.
- Deploy this function to Azure.
Step 2: Call this Function from Power Automate
- Create a new flow in Power Automate.
- Add an HTTP action.
- Configure the HTTP action to call your Azure Function, passing any necessary data.
This approach lets you leverage the full power of C#, while using Power Automate to handle workflow integration and orchestration.