File upload location trouble


  • 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);
            OleDbDataReader dReader;
            dReader = cmd.ExecuteReader();
            SqlBulkCopy sqlBulk = new SqlBulkCopy(strConnection);
            sqlBulk.DestinationTableName = "TestTable";

    jueves, 19 de abril de 2012 18:19


Todas las respuestas