File upload location trouble
-
jueves, 19 de abril de 2012 18:19
Hi Guys
I hope I'm in the right place I have been moved on from a previous forum. I have created a file upload (on VS 2010 in C# for a website) for an excel file to be imported it into database. I have had all the usual connection issues "isam not found" but i think its sorted now I downloaded the 2007 access fix from Microsoft and the error stopped(well there is now a different error). When I browse for the file path "C:\Users\Paul\Documents\Visual Studio 2010\WebSites\Creamery1.1\Book1.xlsx"and put it into the box provided and click the button to import I get this error
"The Microsoft Office Access database engine could not find the object 'C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\10.0\Book1.xlsx'. Make sure the object exists and that you spell its name and the path name correctly."
This is not the path I have chosen so why is this happening?,
here's the code,
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Xml; using System.Data; using System.Web.Security; using System.Web.UI.DataVisualization.Charting; using System.Data.OleDb; using System.Data.SqlClient; public partial class Adminpages_Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { } protected void btnSend_Click(object sender, EventArgs e) { String strConnection = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\ASPNETDB.MDF;Integrated Security=True;User Instance=True"; string path = fileuploadExcel.PostedFile.FileName; string excelConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source="+ path +";Extended Properties=\"Excel 12.0 Xml;HDR=YES;IMEX=1; Persist Security Info=False\""; OleDbConnection excelConnection = new OleDbConnection(excelConnectionString); OleDbCommand cmd =new OleDbCommand("Select [InvoiceDate], [AmountInLitres], [PricePerLitre], [FatContent], [LactoseContent], [AntoBodyCount], [HerdNumber], [milkId] From [Sheet1$]", excelConnection); excelConnection.Open(); OleDbDataReader dReader; dReader = cmd.ExecuteReader(); SqlBulkCopy sqlBulk = new SqlBulkCopy(strConnection); sqlBulk.DestinationTableName = "TestTable"; sqlBulk.WriteToServer(dReader); excelConnection.Close(); } }
Todas las respuestas
-
lunes, 23 de abril de 2012 5:30Moderador
Hi Cheiftain,
Could you please output the context of ‘fileuploadExcel.PostedFile.FileName’ to see if it contains the directory of the file, or just manually set the value of ‘"C:\Users\Paul\Documents\Visual Studio 2010\WebSites\Creamery1.1\Book1.xlsx’ to the string ‘path’ to see if it works?
Here is a similar thread: Connection to Excel from C#.Net (OLEDB).. Please Help.. Also, please pay attention to this article with sample code: Connect the Excel Database from C# .Net.
If the problem cannot be removed, please ask the question on this forum for better assistance.
Stephanie Lv
TechNet Community Support
- Editado Stephanie LvModerator lunes, 23 de abril de 2012 5:52
- Marcado como respuesta Papy NormandModerator jueves, 26 de abril de 2012 17:42
-
jueves, 26 de abril de 2012 17:44Moderador
Hello,
The same question is existing in the SQL Server Integration Services Forum :
and the original poster has marked his last reply as answering his problem...
Have a nice day
Mark Post as helpful if it provides any help.Otherwise,leave it as it is.

