protected void UploadAs_Click(object sender, EventArgs e) { if (DataSetName.Text.Trim().Length != 0 && DataSetUpload.HasFile) { //move most to uploader //handle spaces in file name String uploadPath = System.IO.Path.Combine(System.IO.Path.GetTempPath().ToString(), DataSetUpload.FileName); DataSetUpload.SaveAs(uploadPath); String connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + System.IO.Path.GetTempPath().ToString() + ";Extended Properties='text;HDR=Yes;FMT=Delimited'"; connection = new OleDbConnection(connectionString); OleDbCommand cmd = new OleDbCommand("SELECT * FROM " + DataSetUpload.FileName, connection); da = new OleDbDataAdapter(cmd); connection.Open(); dt = new System.Data.DataTable(); da.Fill(dt); System.Data.DataSet ds = new System.Data.DataSet(DataSetName.Text.Trim()); String[] parameters = { "main" }; ds.Load(dt.CreateDataReader(), System.Data.LoadOption.OverwriteChanges, parameters); Session.Add("table", dt); Session.Add("connection", connection); Session.Add("adapter", da); Registry.Registry registry = Registry.Registry.getRegistry(Session); registry.registerDataset(ds); DatasetList.Items.Add(ds.DataSetName); } }
// UPLOAD BUTTON HANDLER ------------------------------------------------------------------------------------------------------- protected void uploadbutton_Click(object sender, EventArgs e) { // Get button ID Button getbuttonID = (Button)sender; string id = getbuttonID.ID.Replace("_button", ""); // Use button ID to find similarly named upload control ID FileUpload uploadcontrol = (FileUpload)Form.FindControl(id); // Only upload if control has file selected if (uploadcontrol.HasFile) { // Add upload path String savePath = @"c:\temp\"; // Retrieve filename from upload control String fileName = uploadcontrol.FileName; // Save data to web server uploadcontrol.SaveAs(savePath + fileName); // Fill GridView // Establish text driver connection System.Data.Odbc.OdbcConnection csv_connection; System.Data.Odbc.OdbcDataAdapter csv_adapter; // Create temporary data table to store CSV data DataTable csv_data = new DataTable(); // Create connection string and execute connection to CSV string csv_connectionString = @"Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" + savePath + ";"; csv_connection = new System.Data.Odbc.OdbcConnection(csv_connectionString); // Fill adapter with SELECT * query from CSV csv_adapter = new System.Data.Odbc.OdbcDataAdapter("select * from [" + fileName + "]", csv_connection); csv_adapter.Fill(csv_data); // Close CSV connection csv_connection.Close(); // Find GridView and fill GridView filedata = (GridView)Form.FindControl(id + "_table"); filedata.DataSource = csv_data; filedata.DataBind(); // SESSION MODIFICATION // DataSet session_datanew = new DataSet(); session_datanew.Tables.Add(csv_data); session_datanew.DataSetName = "PCADATA"; Registry.Registry registry = Registry.Registry.getRegistry(Session); registry.registerDataset(session_datanew); Analysis.ParameterStream stream = Analysis.ParameterStream.getStream(Session); stream.set("dataSetName", "PCADATA"); //----------------------// } }