title: Get Index of the Excel Sheet using asp.net
body: <p>I am using the following code to extract the sheet names from excel: (See attached code)</p>
  
  <p>But the data is returned sorted by the NAMES of the sheets, and this is the issue. I need to extract the name of the first sheet, by index. </p>
  
  <p>How can I do this?</p>
  
  <pre><code>String sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
                                            "Data Source=" + fileSavePath + newFileName + ".xls; Extended Properties='Excel 8.0;HDR=NO;'";
  
  OleDbConnection objConn = new OleDbConnection(sConnectionString);
  
  objConn.Open();
  
  // Get the data table containg the schema guid.
  DataTable dt = objConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
   string sheetName = "Sheet1$";
  
  if (dt != null) {
      try {
              String[] excelSheets = new String[dt.Rows.Count];
  
              int i = 0;
              foreach (DataRow rows in dt.Rows) {
                       excelSheets[i] = rows["TABLE_NAME"].ToString();
                        i++;
               }
  
               sheetName = excelSheets[0];
          }
          catch {
                   sheetName = "Sheet1$";
            }
     }
  </code></pre>