C# .NET - CSV file will not collate

Asked By Mayra on 22-Feb-11 02:00 PM
PrintDocument printDoc = new PrintDocument();
      printDoc.PrinterSettings.Copies = 2;
        printDoc.PrinterSettings.Collate = true;

The CSV page prints when the button is clicked but it will not collate.

Also, I am working on getting a button to do two things. I have it doing one thing already: When I click it it generates a file and saves it
private void GenerateRejCSV()
    {
      try
      {
        SqlCommand cmdViewRej = new SqlCommand("ViewSubmittedRejuvenateRecords", connection);
        cmdViewRej.CommandType = CommandType.StoredProcedure;
  
        SqlDataReader reader;
  
        reader = cmdViewRej.ExecuteReader();
  
        string sfile = "";
  
        while (reader.Read())
        {
          string s1 = reader["BARRELID"].ToString() + "," + reader["SCANNEDDATE"].ToString() +
            "," + reader["OAKTYPE"].ToString() + "," + reader["ROWNUMBER"].ToString() + "," + reader["USERID"].ToString() +
              "," + reader["SCANNEDTIME"].ToString() + "\r\n";
  
          sfile = sfile + s1;
        }
  
        File.WriteAllText(csvpath + textBoxRejuvenate.Text + ".CSV", sfile);
  
        reader.Close();
  
  
      }

I need it to also print the file that this generates with the same click. Is that possible?
Mohan Raj Aryal replied to Mayra on 22-Feb-11 02:13 PM
Yes it is possible. like you are calling GenerateRajCSV() function on button click event, you can create a  function PrintCSVFile() function. Within this function you can write c# code to print the file. There is a article you can see http://www.c-sharpcorner.com/UploadFile/mahesh/printfile06062007133250PM/printfile.aspx, you can write the similar code (step 3) inside your function.
Mohan Raj Aryal replied to Mayra on 22-Feb-11 02:17 PM
Also regarding collate not working, you will need to keep in mind that the PrintDocument object will take the default printer setting, so If you change the printer setting from control panel it will be okay. However in this case the setting might affect other program as well which are sharing resources. 

So the alternative and I think the best way is to use Drawing method as I have given the link above.