narasiman rao

narasiman rao

  • NA
  • 519
  • 746.8k

how to retrieve file name to be stored in variable

Aug 28 2016 10:07 AM
 
 My code as follows
 
 
int count = 0;
string connectionstring = "Server=(local);initial catalog=Test;Trusted_Connection=True";
SqlConnection sqlConnection = new SqlConnection(connectionstring);
SqlCommand cmd = new SqlCommand();
SqlDataReader reader;
DataSet ds = new DataSet();
cmd.CommandText = "select * from Empdetails";
cmd.CommandText += " where shifttype = @par ";
cmd.Parameters.Add("@par", SqlDbType.Int).Value = j;
cmd.CommandType = CommandType.Text;
cmd.Connection = sqlConnection;
sqlConnection.Open();
reader = cmd.ExecuteReader();
if (reader.HasRows)
{
string filePath = @"C:\Users\God\Desktop\DataDump\" + j + "Excel.xls";
System.IO.StreamWriter sw_In = new System.IO.StreamWriter(filePath);
while (reader.Read())
{
if (count == 0)
{
for (int i = 0; i < reader.FieldCount; i++)
{
sw_In.AutoFlush = true;
sw_In.Write(reader.GetName(i) + "\t");
}
sw_In.Write("\n");
count = 1;
}
for (int i = 0; i < reader.FieldCount; i++)
{
sw_In.AutoFlush = true;
sw_In.Write(reader[i].ToString() + "\t");
}
sw_In.Write("\n");
}
}
reader.Close();
sqlConnection.Close();
 
 when i run the above code two excel file is downloaded in desktop under C Folder as follows
 
 1Excel
 2Excel
 
i want the above  Excel file name to retrieved and displayed. 
 
 for that how can i do to retireve the excel file name and to be displayed

Answers (3)