title: create an excel file in C# with a file save dialog feature . The excel process will be keep running forever in the background
body: <p>I am new to C#, working on a project recently. having problem about saving the excel file part. I want the user to be able to choose where to save the file (BTW, I don't want the file to be read-only). It is like file save dialog. I am using C# console .Net. I can save it to a specific location(with a path) now. Another problem, somehow, the excel file created by the program will be running forever in the background. Can anyone please help me? I have been working on this part for 2 days. Thank you so much.</p>
  
  <p>Code:</p>
  
  <pre><code> private static void excelFile(System.Data.DataTable dtTable,List&lt;Dictionary&lt;string, object&gt;&gt; list)
      {
          Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
              string filepath = AppDomain.CurrentDomain.BaseDirectory;
  
              Console.WriteLine(filepath);
              string filename = @"output1.xlsx";
              Console.WriteLine(filepath + filename);
  
  
        // Microsoft.Office.Interop.Excel.Workbook wkbook = null;
          var wkbook = xlApp.Workbooks.Add(Type.Missing);
  
          wkbook.SaveAs(ReadOnlyRecommended: false);    
  
         _Worksheet wksheet = wkbook.ActiveSheet;
  
               wksheet.Name = "APPLE";
  
          try
          {
              for (var i = 0; i &lt; dtTable.Columns.Count; i++)
              {
                  wksheet.Cells[1, i + 1] = dtTable.Columns[i].ColumnName;
              }
  
              //rows
              for (var i = 0; i &lt; dtTable.Rows.Count; i++)
              {
                  for (var j = 0; j &lt; dtTable.Columns.Count; j++)
                  {
                      wksheet.Cells[i + 2, j + 1] = dtTable.Rows[i][j];
                  }
              }           
  
              //System.IO.FileInfo fileInfo = new System.IO.FileInfo(filename);
  
              //File.SetAttributes(filename, ~FileAttributes.ReadOnly);
              //File.SetAttributes(filename, ~FileAttributes.Hidden);
  
             //xlApp.ActiveWorkbook.Save();
             // wkbook.Save();
              //wkbook.Close();
              //xlApp.ActiveWorkbook.Close();
              xlApp.Workbooks.Close();
  
              xlApp.Quit();
  
          }
          finally
          {
              if (wksheet != null) Marshal.ReleaseComObject(wksheet);
              if (wkbook != null) Marshal.ReleaseComObject(wkbook);
              if (xlApp != null) Marshal.ReleaseComObject(xlApp);
          }
  
      }
  </code></pre>