Dear All ,
I have written below code in simple asp.net web application , It is working fine . But when I converted into SharePoint 2010 Visual web part It it giving error as below
Error 1:
<Excel Path >for System upload .xls' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.
Error 2 :
Microsoft.ACE.OLEDB.12.0' provider is not registered in the local
Error3:
microsoft.jet.oledb.4.0 is not registered
This Error is coming when I am using that app from client machine.
I have written below code in simple asp.net web application , It is working fine . But when I converted into SharePoint 2010 Visual web part It it giving error as below
Error 1:
<Excel Path >for System upload .xls' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.
Error 2 :
Microsoft.ACE.OLEDB.12.0' provider is not registered in the local
Error3:
microsoft.jet.oledb.4.0 is not registered
This Error is coming when I am using that app from client machine.
try { if (fileuploadExcel.HasFile) { //file upload path string fileExtension = Path.GetExtension(fileuploadExcel.PostedFile.FileName); string path = fileuploadExcel.PostedFile.FileName; if ((fileExtension == ".xls") || (fileExtension == ".xlsx")) { //if (fileExtension == ".xls") //{ // string excelConnectionString = @"PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" + path + ";EXTENDED PROPERTIES=" + "\"EXCEL 8.0;HDR=YES;\""; //} //else if (fileExtension == ".xlsx") //{ string excelConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;Persist Security Info=False"; //} //Create connection string to Excel work book // @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;Persist Security Info=False"; //Create Connection to Excel work book OleDbConnection excelConnection = new OleDbConnection(excelConnectionString); //Create OleDbCommand to fetch data from Excel OleDbCommand cmd = new OleDbCommand("Select [Sno ],[Distributor],[Region] ,[Destination],[ZR_FC_Point30] ,[ZR_FC_Point33] ,[ZR_FC_Point35] ,[ZR_FC_Point45] ,[ZR_FC_Point58] ,[ZR_PRT_Point30] ,[ZR_PRT_Point33] ,[ZR_PRT_Point35] ,[ZR_PRT_Point45] ,[ZR_PRT_Point58] ,[ZR_PS_Point30] ,[ZR_PS_Point33] ,[ZR_PS_Point35] ,[ZR_PS_Point45] ,[ZR_PS_Point58] ,[PZR_FC_Point30] ,[PZR_FC_Point33] ,[PZR_FC_Point35] ,[PZR_FC_Point45] ,[PZR_FC_Point58] ,[PZR_PRT_Point30] ,[PZR_PRT_Point33] ,[PZR_PRT_Point35] ,[PZR_PRT_Point45] ,[PZR_PRT_Point58] ,[PZR_PS_Point30] ,[PZR_PS_Point33] ,[PZR_PS_Point35] ,[PZR_PS_Point45] ,[PZR_PS_Point58] ,[WT_Point45] ,[WT_Point50] ,[TPS_Point45] ,[TPS_Point50] ,[Purlin2000] ,[Purlin4000] ,[Purlin6000] from [UpdatedSheet$]", excelConnection); excelConnection.Open(); OleDbDataReader dReader; dReader = cmd.ExecuteReader(); SqlBulkCopy sqlBulk = new SqlBulkCopy(Connection); //Give your Destination table name sqlBulk.DestinationTableName = "mPrice_allCatPriceSheet"; sqlBulk.WriteToServer(dReader); excelConnection.Close(); ExcelUploaddetails(); } else { Lbmsg.Visible = true; Lbmsg.Text = "Only Excel Files are allowed !!!"; } } else { Lbmsg.Visible = true; Lbmsg.Text = "There is no file selected !!!!"; } } catch (Exception ex) { Lbmsg.Visible = true; Lbmsg.Text = ex.Message.ToString(); } finally { }
Thanks in Advance !!!