I am creating an Excel to JSON parser and everything works good, but I have confusion. Currently my application displays the result in the console, and I want to modify it and write the result to the disc on my local machine as a file named output.json.
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Data.OleDb;
using System.Linq;
namespace ExcelToJSON
{
    class Program
    {
        static void Main(string[] args)
        {
            var path = @"C:\Users\demir.mahmutovic\Desktop\aaa.xlsx";
            string sheetName = "Sheet1";
            var connstr = string.Format(@"
            Provider=Microsoft.ACE.OLEDB.12.0;
            Data Source={0};
            Extended Properties=""Excel 12.0 Xml;HDR=YES""", path);
            using (var conn = new OleDbConnection(connstr))
            {
                conn.Open();
                var cmd = conn.CreateCommand();
                cmd.CommandText = String.Format(@"SELECT * FROM [{0}$]",
                sheetName
                );
                using (var rdr = cmd.ExecuteReader())
                {
                    //LINQ query - when executed will create anonymous objects for each row
                    var query =
                        (from DbDataRecord row in rdr
                         select row).Select(x =>
                         {
                             //dynamic item = new ExpandoObject();
                             Dictionary<string, object> item = new Dictionary<string, object>();
                             item.Add(rdr.GetName(0), x[0]);
                             item.Add(rdr.GetName(1), x[1]);
                             item.Add(rdr.GetName(2), x[2]);
                             item.Add(rdr.GetName(3), x[3]);
                             item.Add(rdr.GetName(4), x[4]);
                             item.Add(rdr.GetName(5), x[5]);
                             item.Add(rdr.GetName(6), x[6]);
                             item.Add(rdr.GetName(7), x[7]);
                             item.Add(rdr.GetName(8), x[8]);
                             item.Add(rdr.GetName(9), x[9]);
                             item.Add(rdr.GetName(10), x[10]);
                             item.Add(rdr.GetName(11), x[11]);
                             item.Add(rdr.GetName(12), x[12]);
                             item.Add(rdr.GetName(13), x[13]);
                             item.Add(rdr.GetName(14), x[14]);
                             item.Add(rdr.GetName(15), x[15]);
                             item.Add(rdr.GetName(16), x[16]);
                             item.Add(rdr.GetName(17), x[17]);
                             item.Add(rdr.GetName(18), x[18]);
                             return item;
                         });
                    //Generates JSON from the LINQ query
                    var json = JsonConvert.SerializeObject(query);
                    var result = json;
                    Console.WriteLine(result);
                    Console.ReadLine();
                    //return json;
                }
            }
        }
    }
}
Can anyone guide me and tell me if this is possible or not and what is the best way to resolve this problem. I would be very thankful,
 
     
    