Copy code code as follows:
if (this. Fileupload1.postedfile!= null)
{
String filename = this. FileUpload1.FileName.ToString ();
String path = @Server. MapPath (". /file/") + filename;
this. FileUpload1.PostedFile.SaveAs (path);
//Read user uploaded excle file
string conn= "Provider = microsoft.jet.oledb.4.0;D ata Source = ' +path+ '"; Extended Properties=excel 8.0 ";
OleDbConnection olecon = new OleDbConnection (conn);
Olecon. Open ();
//Note the table name, after opening the Excel file, the excle name of the bottom part of the page,
///default is $sheet1, $Sheet 2, $Sheet 3
String sql = "SELECT * from [$Sheet 1]";
OleDbDataAdapter Oleda = new OleDbDataAdapter (sql,conn);
Oleda. Fill (DS);
Olecon. Close ();
this. Gridview1.datasource = ds;
this. Gridview1.databind ();
String file_name = "20091126002.xml";
String xml_path = @Server. MapPath (".. /reports/xml/") + file_name;
ds. WriteXml (Xml_path);
DS. Dispose ();
}