Posts

CSV using XmlNode

 To create a CSV from an XmlNode in C#, you can follow these steps: 1. Parse the XML structure using XmlNode. 2. Extract the data you need from child nodes. 3. Write the CSV content using a StringBuilder or directly with StreamWriter. Here's a sample code snippet: using System; using System.IO; using System.Text; using System.Xml; public class XmlToCsvConverter {     public static void ConvertXmlNodeToCsv(XmlNode rootNode, string csvFilePath)     {         StringBuilder csvContent = new StringBuilder();         // Assuming all child nodes have the same structure         // Add header         if (rootNode.HasChildNodes)         {             XmlNode firstRow = rootNode.FirstChild;             for (int i = 0; i < firstRow.ChildNodes.Count; i++)             {     ...

Controller_Model. cs

Controller using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using NZWalks.API.Helper; using NZWalks.API.Models; using System.Net; namespace NZWalks.API.Controllers {     [ApiController]     [Route("api/[controller]")]     public class ConnectionController : ControllerBase     {         private readonly IConfiguration _configuration;         public ConnectionController(IConfiguration configuration)         {             _configuration = configuration;         }         [HttpGet("validate")]         public IActionResult ValidateAllConnections()         {             var hostname = Dns.GetHostName();             var connectionStrings = new List<ConnectionItem>();           ...

New API

 using System; using System.Collections.Generic; using System.Net.Http; using System.Net.Http.Headers; using System.IO; using System.Text.Json; using System.Threading.Tasks; class Program {     private static readonly HttpClient client = new HttpClient();     static async Task Main(string[] args)     {         string token = "your_token_here"; // 🔐 Replace with your actual token         string baseUrl = "https://api-stage.marmin.ai";         string createdDate = "2025-03-03";         // 🛡️ Add Authorization header         client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);         string idsUrl = $"{baseUrl}/api/invoices/ids?created_on={createdDate}";         try         {             // 1) Get array of IDs     ...

Api

  --- Step-by-Step: API Call with Bearer Token Header --- ✅ STEP 1: Add a Config Class for Token (Optional but Clean) File: AppConfig.cs (root folder) namespace ApiConsoleApp {     public static class AppConfig     {         // You can load this from config file or env variable too         public static string BearerToken = "YOUR_DYNAMIC_BEARER_TOKEN_HERE";         public static string ApiBaseUrl = "https://your-api-base-url.com/";     } } --- ✅ STEP 2: Modify API Client to Use Bearer Token File: ApiClients/UserApiClient.cs using System; using System.Net.Http; using System.Net.Http.Headers; using System.Text; using System.Threading.Tasks; using ApiConsoleApp.Models; using Newtonsoft.Json; namespace ApiConsoleApp.ApiClients {     public class UserApiClient     {         private readonly HttpClient _httpClient;         public UserApiCli...

Popular posts from this blog

String Program in C#

CSV using XmlNode

Controller_Model. cs