ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Import Excel file without saving in folder in ASP.Net<p>1. The FileName property is the Client end path while you need to use the Server side path for reading Excel file.</p> <p>2. OLEDB can only read for file path. If you want to read directly from FileUpload, you need to use Closed XML.</p> <p>Refer my article</p> <h1 class="header"><a title="Read and Import Excel data to DataTable using ClosedXml in ASP.Net with C# and VB.Net'a" href="https://www.aspsnippets.com/Articles/Read-and-Import-Excel-data-to-DataTable-using-ClosedXml-in-ASPNet-with-C-and-VBNet.aspx">Read and Import Excel data to DataTable using ClosedXml in ASP.Net with C# and VB.Net</a></h1> <p>Just remove the following lines</p> <pre class="brush: csharp"> string filePath = Server.MapPath(&#34;~/Files/&#34;) + Path.GetFileName(FileUpload1.PostedFile.FileName); FileUpload1.SaveAs(filePath);</pre> <p>and replace following line</p> <pre class="brush: csharp">using (XLWorkbook workBook = new XLWorkbook(filePath))</pre> <p>with</p> <pre class="brush: csharp"> using (XLWorkbook workBook = new XLWorkbook(FileUpload1.PostedFile.InputStream))</pre> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/936948/Import-Excel-file-without-saving-in-folder-in-ASPNet/https://www.aspforums.net:443/Threads/936948/Import-Excel-file-without-saving-in-folder-in-ASPNet/Thu, 31 May 2018 00:57:13 GMTImport Excel file without saving in folder in ASP.Net<p>Hi Mudassar,</p> <p>&nbsp;</p> <p>When i try run in localhost(IIS), I get the following error.</p> <p>attached code as well.</p> <h2><em>Object reference not set to an instance of an object.</em></h2> <p><font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif "><strong> Description: </strong>An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. <strong> Exception Details: </strong>System.NullReferenceException: Object reference not set to an instance of an object. <strong>Source Error:</strong> </font></p> <table width="100%" bgcolor="#ffffcc"> <tbody> <tr> <td><code> An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.</code></td> </tr> </tbody> </table> <p><font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif "> <strong>Stack Trace:</strong> </font></p> <table width="100%" bgcolor="#ffffcc"> <tbody> <tr> <td> <pre>[NullReferenceException: Object reference not set to an instance of an object.] Avaya_ID.AvayaID.BtnUpload_Click(Object sender, EventArgs e) +1420 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +11764988 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +149 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1664 </pre> </td> </tr> </tbody> </table> <p>&nbsp;</p> <p>&nbsp;</p> <pre class="brush: csharp">tring strFileType = Path.GetExtension(FileUpload1.FileName).ToLower(); string path = FileUpload1.PostedFile.FileName; SqlBulkCopy oSqlBulk = null; // SET A CONNECTION WITH THE EXCEL FILE. OleDbConnection myExcelConn = new OleDbConnection (&#34;Provider=Microsoft.ACE.OLEDB.12.0;Data Source=&#34; + path + &#34;;Extended Properties=\&#34;Excel 12.0;HDR=Yes;IMEX=2\&#34;&#34;); try { myExcelConn.Open(); // GET DATA FROM EXCEL SHEET. OleDbCommand objOleDB = new OleDbCommand(&#34;SELECT *FROM [Sheet1$] where Avaya_ID IS NOT NULL&#34;, myExcelConn); // READ THE DATA EXTRACTED FROM THE EXCEL FILE. OleDbDataReader objBulkReader = null; objBulkReader = objOleDB.ExecuteReader();</pre> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/936948/Import-Excel-file-without-saving-in-folder-in-ASPNet/https://www.aspforums.net:443/Threads/936948/Import-Excel-file-without-saving-in-folder-in-ASPNet/Fri, 01 Jun 2018 13:25:33 GMTImport Excel file without saving in folder in ASP.Net<p>Will you please let us know which line you are getting the error?</p>https://www.aspforums.net:443/Threads/936948/Import-Excel-file-without-saving-in-folder-in-ASPNet/https://www.aspforums.net:443/Threads/936948/Import-Excel-file-without-saving-in-folder-in-ASPNet/Sun, 03 Jun 2018 23:25:22 GMTImport Excel file without saving in folder in ASP.Net<p>Hi,</p> <p>Share the Line number and let us know whoch line error is coming.</p>https://www.aspforums.net:443/Threads/936948/Import-Excel-file-without-saving-in-folder-in-ASPNet/https://www.aspforums.net:443/Threads/936948/Import-Excel-file-without-saving-in-folder-in-ASPNet/Mon, 04 Jun 2018 03:44:39 GMTImport Excel file without saving in folder in ASP.Net<p>Hi Mudassar,</p> <p>&nbsp;</p> <p>This is the line where im getting an error</p> <pre class="brush: csharp"> new OleDbCommand(&#34;SELECT *FROM [Sheet1$] where Avaya_ID IS NOT NULL&#34;, myExcelConn);</pre> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/936948/Import-Excel-file-without-saving-in-folder-in-ASPNet/https://www.aspforums.net:443/Threads/936948/Import-Excel-file-without-saving-in-folder-in-ASPNet/Mon, 04 Jun 2018 09:38:54 GMTImport Excel file without saving in folder in ASP.Net<p>Hi <a class="username" rel="Mohdsalim"> Mohdsalim</a>,</p> <p>As per your question you don't want to save the file in directory. So you need to use&nbsp;ClosedXml.</p> <p>Refer below article.</p> <h1 class="header"><a title="Read Excel file using FileUpload without saving in Folder in ASP.Net'a" href="https://www.aspsnippets.com/Articles/Read-Excel-file-using-FileUpload-without-saving-in-Folder-in-ASPNet.aspx">Read Excel file using FileUpload without saving in Folder in ASP.Net</a></h1> <p>Once you get the DataTable by reading the excel you can use SQLBulkCopy to import data to Database.</p> <h1 class="header"><a title="Using SqlBulkCopy to import Excel SpreadSheet data into SQL Server in ASP.Net using C# and VB.Net'a" href="https://www.aspsnippets.com/Articles/Using-SqlBulkCopy-to-import-Excel-SpreadSheet-data-into-SQL-Server-in-ASPNet-using-C-and-VBNet.aspx">Using SqlBulkCopy to import Excel SpreadSheet data into SQL Server in ASP.Net using C# and VB.Net</a></h1>https://www.aspforums.net:443/Threads/936948/Import-Excel-file-without-saving-in-folder-in-ASPNet/https://www.aspforums.net:443/Threads/936948/Import-Excel-file-without-saving-in-folder-in-ASPNet/Tue, 05 Jun 2018 01:11:59 GMT