Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi

I had added a openfile dialog for Importing Excel Files. I need to validate the input file like whether it has specified columns and atleast one row of data.

Is it possible to validate before saving the file to server ?
How to read the contents of excel file and export to datatable or dataset.

C#
private void ImportButton_Click(object sender, RoutedEventArgs e)
{           
   OpenFileDialog openFileDialog = new OpenFileDialog();
   openFileDialog.Multiselect = false;
   openFileDialog.Filter = "Excel Files(*.xlsx)|*.xlsx";

   if (openFileDialog.ShowDialog() == true)
   {
      this.FileTextBox.Text = openFileDialog.File.Name;
      this.FileTextBox.IsReadOnly = true;
      FileStream myStream = openFileDialog.File.OpenRead();                  
   }
}
Posted
Updated 7-Oct-14 0:01am
v2
Comments
Maciej Los 7-Oct-14 5:55am    
You can use ADO.NET.

1 solution

See, for instance this Code Project article: "Working with Excel Using C#"[^].
As already proposed by Maciej, you could alternatively use ADO.NET for the same purpose (see, for instance this page "Reading Excel From C#"[^]).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900