asp.net - The Microsoft Jet database engine cannot open the file -
I am writing a code for query, using the SQL using the CSV file is my code that works perfectly fine
string file directory = @ "C: \ technical exam \ GskTest \ Csv \ SampleData.csv"; String strCSVConnString = "provider = Microsoft.Jet.OLEDB.4.0; data source =" + file directory + "; extended property = 'text; hdr = yes;'"; Select the number of string sqlCust = "sample data ccv" (order_id), order_id, contact_id "+" order_id group, contact_id "+ 1dcc" by order "; string sqlProd =" selection number (order_id), sample_data.csv Product_id "+" by Group "+" Order 1 by DCC ";; string sql order =" Count Count (Order_ID) "from SampleData.csv" + "Order by 1 DCCC"; OleDbConnection con = New OleDbConnection ("Provider = Microsoft.Jet.OleDb.4.0; Data Source =" + System.IO.Path.GetDirectoryName (File Directory) + "Extended Properties = \" text; HDR = Yes; FMT = Delimited \ ""); Con.Open (); OleDbDataAdapter daCust = New OleDbDataAdapter (sqlCust, con); Datatile dtCust = new datatale (); DaCust.Fill (dtCust); OleDbDataAdapter daProd = New OleDbDataAdapter (sqlProd, con); Datatelle dtProd = new datatale (); DaProd.Fill (dtProd); OleDbDataAdapter daOrders = New OleDbDataAdapter (sqlOrders, con); Datatelle dtOrders = new datatyll (); DaOrders.Fill (dtOrders); Con.Close ();
But when I am trying to call the same code from the function that gets the file path from the asp.net file upload control, then it does not work. Please see the code below.
Secure Zero btnSubmit_Click (Object Sender, EventArgs e) {if (fupPath.HasFile) {string filename = Path.GetFileName (fupPath.FileName); String csv_file_path = Path.Combine (Server.MapPath ("~ / Csv"), file name); FupPath.SaveAs (csv_file_path); Summery (csv_file_path); Datatelle csvData = GetDataTabletFromCSVFile (csv_file_path); reaction. Write ("Count of Rows:" + csvdata.rows.Count); // dtSummary (csvData); }} Secure Zero Saturation (String Filename) {// String File Directory = @ "C: \ Technical Test \ Gascate \ CSV \ Sampled Data CSV"; String file directory = filename; // string strCSVConnstring = "provider = Microsoft.Jet.OLEDB.4.0; data source =" // + System.IO.Path.GetDirectoryName (file directory) + "; extended property = 'text; hdr = yes; fmt = direct Gone \ '"; Select the number of string sqlCust = "sample data ccv" (order_id), order_id, contact_id "+" order_id group, contact_id "+ 1dcc" by order "; string sqlProd =" selection number (order_id), sample_data.csv Product_id "+" by Group "+" Order 1 by DCC ";; string sql order =" Count Count (Order_ID) "from SampleData.csv" + "Order by 1 DCCC"; OleDbConnection conn = New OleDbConnection ("Provider = Microsoft.Jet.OleDb.4.0; Data Source =" + System.IO.Path.GetDirectoryName (file directory) + "Extended Properties = \" text; HDR = Yes; FMT = Delayed \ ""); // OLDBIC CONCONNECTION conn = new allelebonection (strasological string); Conn.Open (); OleDbDataAdapter daCust = New OleDbDataAdapter (sqlCust, conn); Datatile dtCust = new datatale (); DaCust.Fill (dtCust); DaCust.Dispose (); OleDbDataAdapter daProd = New OleDbDataAdapter (sqlProd, conn); Datatelle dtProd = new datatale (); DaProd.Fill (dtProd); DaProd.Dispose (); OleDbDataAdapter daOrders = New OleDbDataAdapter (sqlOrders, conn); Datatelle dtOrders = new datatyll (); DaOrders.Fill (dtOrders); DaOrders.Dispose (); Conn.Close (); }
You have to call the name of a sheet sheetname $
Instead of the filename SampleData.csv
.
For example, select
number (order_id), order_id, contact_id [SheetName $]
generally , That is how you get a file path in ASP.NET, because you do not know the drive letter where your web application is hosted. In addition to this, you do not have access to any file located outside the web application.
var filePath = string.Format ("{0} App_Data \\ ExportImport \\ {1}", httpRTime .AppDomainAppPath, "SampleData.csv");
Comments
Post a Comment