Note that there are some explanatory texts on larger screens.

plurals
  1. POStart Process - then add to it later (MS Excel Example)
    primarykey
    data
    text
    <p>I've got a data collection routine that takes about 10 seconds to run, then it saves data to a CSV file:</p> <pre><code>string file = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Book1.csv"); StreamWriter streamWriter1 = new StreamWriter(File.Open(file, FileMode.Create, FileAccess.Write)); DataTable table = GetMyData(); // takes about 10 seconds foreach (DataRow row in table.Rows) { object[] item = row.ItemArray; for (int i = 0; i &lt; item.Length; i++) { streamWriter1.Write(item.ToString() + ","); } streamWriter1.WriteLine(); } streamWriter1.Close(); Process.Start("Excel", "book1.csv"); </code></pre> <p>Excel takes a few moments to start as well (5 to 10).</p> <p>I'd like to modify this technique so that I call Excel just before my data collection so the application will be running by the time I have collected the data, then just have it display the file with the data.</p> <p>With this in mind, here's what I modified the code to, but it always tells me the file is not there (even though it is):</p> <pre><code>Process excel = Process.Start("Excel"); if (excel != null) { string file = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Book1.csv"); StreamWriter streamWriter1 = new StreamWriter(File.Open(file, FileMode.Create, FileAccess.Write)); DataTable table = GetMyData(); // takes about 10 seconds foreach (DataRow row in table.Rows) { object[] item = row.ItemArray; for (int i = 0; i &lt; item.Length; i++) { streamWriter1.Write(item.ToString() + ","); } streamWriter1.WriteLine(); } streamWriter1.Close(); for (int i = 0; i &lt; 100; i++) { // simulate the data collection routine Thread.Sleep(100); } excel.StartInfo.Arguments = file; excel.StartInfo.ErrorDialog = true; excel.StartInfo.UseShellExecute = false; excel.StartInfo.WorkingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); try { excel.Start(); } catch (Exception err) { Console.WriteLine(err.Message); // &lt;= Message is "The system cannot find the file specified" } } </code></pre> <p>Any thoughts? How would I correctly send the file to the active process?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload